Some Android phones not opening “About device” page in Settings?

Viewed 294

Some Android phones don't do anything when the the code below is ran. It's supposed to open the "About device" page in Settings.

For example, I know for a fact that it has no effect on the Huawei Y9 Prime 2019 running Android 10.

startActivity(new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS));

What's the best way to safeguard against this issue when it occurs? (In my app, I open this page to ask the user to perform a specific action there)

2 Answers

Use PackageManager.resolveActivity() to check whether such an Activity exists. If that returns null, there is no activity that matches the Intent and you have to guide your customers to the settings in another way:

Intent intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, 0);
if (resolveInfo == null) {
    // help customers by describing how to get to the device info settings

} else {
    startActivity(intent);
}

If an activity is not found, the method startActivity will throw android.content.ActivityNotFoundException. You should catch this exception and notify the user:

try {
    startActivity(new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS));
} catch (ActivityNotFoundException e) {
    // Notify the user, eg. using a popup so they can open settings manually 
}

Related