1

I am trying to use UsageStatsManager on an Android Wear device.

What I did:

I am requesting the permission for it on the mobile app that is running on my phone. After the permission was given by the user, I can access the usage stats data. Then I created a UsageStatsManager on the wear app and tried to access the usage stats data there. However, on the watch, I do not have the permission to do that and I can not ask for permission. To check if the permission was given by the user I used:

private boolean isPermissionGranted(){
    try{
        PackageManager packageManager = getPackageManager();
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0);
        AppOpsManager appOpsManager = (AppOpsManager) 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;
    }
}

This returns true on the phone but false on the watch.

The problem:

I can ask the user for permission to use UsageStatsManager on the phone but I can not do that on the watch because the setting does not exist. Has anyone figured out if it is possible to get UsageStatsManager running on a watch?

4

1 回答 1

1

Usage Permission intent isn't possible on Wear.

Same goes for Overlay (Settings.canDrawOverlays()) though at least you can use lower target to overcome it.

Also with latest Android N emulator this isn't resolved.

于 2016-07-10T18:28:19.157 回答