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

前端 未结 3 413
无人共我
无人共我 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

    Does someone know how to listen to changes in that setting, with code similar or analogous to

    Context context = configuration.getContext();
    ContentResolver resolver = context.getContentResolver();
    resolver.registerContentObserver(Settings.System.CONTENT_URI, true, observer = new TimeoutSettingContentObserver(context, new Handler()));
    

    Here is the code:

    PackageManager packageManager = getPackageManager(); 
    final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0); 
    appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE); 
    appOpsManager.startWatchingMode(AppOpsManager.OPSTR_GET_USAG‌​E_STATS, 
            applicationInfo.packageName,
            new AppOpsManager.OnOpChangedListener(){ 
                @Override public void onOpChanged(String op, String packageName) {
                    int mode = appOpsManager.checkOpNoThrow(op, applicationInfo.uid, packageName); 
                    boolean enabled = mode == AppOpsManager.MODE_ALLOWED; 
                } 
            });
    
    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-11 07:38

    you need add activity to manifest xml like that

    (under application)

    <activity
           android:name="com.yournamespace.yourclassname"
           android:label="@string/app_name" >           
    </activity>
    
    0 讨论(0)
提交回复
热议问题