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
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