我需要从我的应用程序中打开 Usage Stats 设置。对于大多数手机,一切正常:
startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS));
但是,有些手机(例如华为 Y6 Pro)会引发安全异常java.lang.SecurityException: Permission Denial: starting Intent { act=android.settings.USAGE_ACCESS_SETTINGS cmp=com.android.settings/.Settings$UsageAccessSettingsActivity } from ProcessRecord{3f032f8b 18712:com.example.pro/u0a924} (pid=18712, uid=10924) not exported from uid 1000
有没有办法检查我是否可以执行startActivity
并且不会抛出任何异常?