6

I am getting this error on my huawei nexus 6p while putting the app in protected apps list.

"UncaughtException: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.huawei.systemmanager/com.huawei.systemmanager.optimize.process.ProtectActivity}; have you declared this activity in your AndroidManifest.xml?"

and i am using this code to put the app in protected apps list

if ("huawei".equalsIgnoreCase(Build.MANUFACTURER) && !settingsManager.getKeyStateProtectedApp()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Is app killing?").setMessage("Add LastingSales to protected apps list to keep it running in background.")
                        .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Intent intent = new Intent();
                                intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
                                startActivity(intent);
                                settingsManager.setKeyStateProtectedApp(true);
                            }
                        }).create().show();
            }

Problem here is that this is not an activity of my own that i can declare in manifest. Do i still have to declare it in manifest ? if i do have to then how can i do this ?

SOLVED the reason was that huawei nexus 6p has pure android and hence there is no such activity. but code was falling there because Build.MANUFACTURER returns "huawei". however Build.BRAND returns "google" so added additional check as

if ("huawei".equalsIgnoreCase(Build.MANUFACTURER) && !"google".equalsIgnoreCase(Build.BRAND) && !settingsManager.getKeyStateProtectedApp()
Ibtisam Asif
  • 67
  • 1
  • 1
  • 7
  • 1
    add the activity you are using in Manifest.xml –  Dec 13 '17 at 06:03
  • You'll need to add the activity to the manifest, even if it's part of a third party module. – Abhishek Tiwari Dec 13 '17 at 06:16
  • 1
    My code works perfect on some other huawei devices like huawei honor h30-u10. Without declaration. why not on huawei nexus 6p. if i need to declare it in manifest then how ? – Ibtisam Asif Dec 13 '17 at 06:38
  • @IbtisamAsif Have you tried [this solutions](https://stackoverflow.com/questions/31638986/protected-apps-setting-on-huawei-phones-and-how-to-handle-it/35220476)? – Harshad Prajapati Dec 13 '17 at 06:39
  • @Hardshad Prajapati i had picked the code from [link](https://stackoverflow.com/questions/31638986/protected-apps-setting-on-huawei-phones-and-how-to-handle-it/35220476) It was working perfect until today i tested in Nexus 6p. My problem isn't identified by anyone there. – Ibtisam Asif Dec 13 '17 at 06:50

3 Answers3

0

The if clause needs to carefully check the manufacturer and the brand so it will run on just the phones it's appropriate for.

J_H
  • 17,926
  • 4
  • 24
  • 44
0

I use this method to check if a device can open such intent but still, it returns true for Huawei but still crashes, hate this manufacture

fun Intent.canBeHandled(packageManager: PackageManager): Boolean {
    return resolveActivity(packageManager) != null
}

Fatal Exception: android.content.ActivityNotFoundException Unable to find explicit activity class {com.huawei.systemmanager/com.huawei.systemmanager.optimize.process.ProtectActivity}; have you declared this activity in your AndroidManifest.xml? com.helge.droiddashcam.base.utils.IntentUtil.autoStartSettings

user924
  • 8,146
  • 7
  • 57
  • 139
0

The Huawei Nexus 6P runs Google software on Huawei hardware; so there are no com.huawei packages present. While try and catch is the proper way to prevent ActivityNotFoundException, no matter the device. One should always do so, because one never can be certain.

try {
    Intent intent = new Intent();
    intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
    startActivity(intent);
} catch (ActivityNotFoundException e) {
    Log.d(LOG_TAG, "com.huawei.systemmanager.optimize.process.ProtectActivity not found.");
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216