3

I am trying to check my app as a protected app in Infinix phones programatically .. but it seems to be impossible so instead of that I am trying to start Protected apps activity which exist in XManager >> Settings >> Protected apps

I succeeded to just open XManager by this code

try {
      startActivity(new Intent().setClassName("com.transsion.mobilebutler",
                    "com.transsion.mobilebutler.MainActivity"));

        } catch (Exception e) {
            Log.d("tag", "e " + e.toString());
        }

I can't do anything else programatically

when I tried to start Settings activity by this code

 try {
            startActivity(new Intent().setComponent(new ComponentName("com.transsion.mobilebutler",
                    "com.transsion.mobilebutler.SettingsActivity")));

        } catch (Exception ex) {
            Log.d("tag", "ex " + ex.toString());

        }

I got this Exception

  java.lang.SecurityException: Permission Denial: starting Intent

also I tried to start protected apps directly but again I got the same Excepion

try {
            Intent intent = new Intent();
            intent.setClassName("com.transsion.mobilebutler", 
                    "com.transsion.mobilebutler.applicationmanager.view.activities.MemoryAccelerateWhitelistActivity");
            startActivity(intent);
        } catch (Exception e) {
            Log.d("tag", "e " + e.toString());

Updated

Some answers of this Exception suggest to add android:exported="true" to manifest when I add activity I got Unresolved class error

    <activity android:name="com.transsion.mobilebutler.SettingsActivity" android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
        </intent-filter>
    </activity>

Is there any way to solve this problem ?

Islam Ahmed
  • 668
  • 9
  • 19
  • 1
    Did you set `android:exported="true"` in your `AndroidManifest.xml`? Check this link: https://stackoverflow.com/questions/19829507/android-java-lang-securityexception-permission-denial-starting-intent – ʍѳђઽ૯ท Oct 03 '18 at 08:44
  • I don't know how to use it ? because I didn't declare Protected apps activity in manifest ,, How can i do that ? – Islam Ahmed Oct 03 '18 at 08:46
  • 1
    Would you please add whole logcat after `starting Intent` ? Also, did you try by removing `intent-filter` in the suggested way? – ʍѳђઽ૯ท Oct 03 '18 at 08:59
  • hard to publish the whole logcat here ,If you solved this problem before can you share your code ,please? – Islam Ahmed Oct 03 '18 at 09:22

1 Answers1

2

You obviously cannot do this. The reason you are getting the "permission denied" exceptions is that the Activity you are trying to launch is not "exported" (ie: not launchable by apps other than the one it belongs to).

You can only start the main settings screen. Any app is allowed to launch this. The specific setting screen for "protected apps" can only be launched by the settings application itself.

You don't need to set android:exported="true" on anything in your app because the exception is thrown because the Activity you are trying to start is not exported.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • 1
    thanks for answer .. If it is impossible How can I add my App to Protected apps programatically ? what is the best solution for this problem ? – Islam Ahmed Oct 03 '18 at 13:38
  • 2
    You cannot add your app to the list of protected apps programatically. Only the user can do that. All you can do is show the user a Dialog explaining to him that you need him to add your app to the list of protected apps and you can offer to open the settings screen for him. That's it. It isn't a nice solution, but it is the only choice you have. Other than paying the manufacturer to preinstall your app on the device. – David Wasser Oct 03 '18 at 14:48
  • 1
    See https://stackoverflow.com/questions/31638986/protected-apps-setting-on-huawei-phones-and-how-to-handle-it – David Wasser Oct 03 '18 at 14:49
  • You should accept the answer if it was helpful. That will remove the question from the list of unanswered questions. – David Wasser Oct 04 '18 at 08:18