ActivityNotFoundException in Lollipop when trying to launch activity with intent android.settings.USAGE_ACCESS_SETTINGS

前端 未结 3 415
无人共我
无人共我 2020-12-11 07:00

I am trying to get the permission to access app usage data using this permission. THis is only being done for Lollipop and when I start activity with this intent (android.se

3条回答
  •  隐瞒了意图╮
    2020-12-11 07:12

    I checked the same code on google nexus 5.0 and emulator , it works fine .It didnot show any error .Intent works fine and Apps usage acess actvity is also launched though it didnot list any apps under this .

    Under settings -->security --> APPS usage -- first check your device list any apps .

    Try the below code and check whether your application has usage acess enable

    Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
    startActivity(intent);
    
    
    try {
    PackageManager packageManager = context.getPackageManager();
    ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
    AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName);
    return (mode == AppOpsManager.MODE_ALLOWED);
    
    } catch (PackageManager.NameNotFoundException e) {
    return false;
    }
    

    And also you can refer to this link this link

提交回复
热议问题