8

This issue is happening on Android 5.0 Lollipop only. I dont have access to a phone with Lollipop, I have developed the code in Genymotion Android Emulator but this issue does not happen in the emulator. I am only getting failing stacktraces from users' phones.

My Code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
    startActivity(intent);
} 

The App crashes and the stacktrace I am getting from users:

android.content.ActivityNotFoundException: No Activity found to handle Intent {     act=android.settings.USAGE_ACCESS_SETTINGS }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1765)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1485)
at android.app.Activity.startActivityForResult(Activity.java:3780)
at android.app.Activity.startActivityForResult(Activity.java:3741)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:849)
at android.support.v4.app.Fragment.startActivity(Fragment.java:880)
at     com.myapp.myfirstapp.fragments.addablock.apps.Fragment_appsselect_addblock$2.onClick(Fragment_ appsselect_addblock.java:147)
at android.view.View.performClick(View.java:4763)
at android.view.View$PerformClick.run(View.java:19821)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5274)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
user1406716
  • 9,565
  • 22
  • 96
  • 151
  • Check [this](http://stackoverflow.com/questions/27097743/error-in-manifest-xml-when-adding-package-usage-stats-android-lollipop) Also check [this](http://stackoverflow.com/questions/27215013/check-if-my-application-has-usage-access-enabled) – Noor Nawaz Jan 10 '15 at 09:56
  • thanks @NoorNawaz - but seems like I am starting the activity with the intent the same way... cant find the problem. – user1406716 Jan 10 '15 at 10:21
  • It means activity you're trying to start is not in that package where you expect to be. – Noor Nawaz Jan 10 '15 at 12:08
  • 1
    Tested and confirmed this is an issue on Samsung Galaxy S5 SM-G900I running Android 5.0 G900IZTU1BOA1 firmware. The usage access settings screen can be accessed by the user, but not with the `Settings.ACTION_USAGE_ACCESS_SETTINGS` intent. `Intent componentNameIntent = new Intent(); componentNameIntent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$UsageAccessSettingsActivity"));` also doesn't work. – Sam Feb 25 '19 at 20:23

1 Answers1

8

I am seeing this crash too. It seems that LG has removed the newly introduced Usage Permission Setttings screen from their version of Lollipop.

caspii
  • 849
  • 7
  • 20
  • Yep, exactly. I tried on MotoX and it works fine. Does LG have any other way to grant access the Usage Permission to apps? I dont have a LG phone with Lollipop to try myself. (This would be the right answer, i will mark it as such) – user1406716 Jan 23 '15 at 16:59
  • Indeed, it works on a Nexus 10, and not on the LG G3. The settings submenu "Apps with usage access" is also missing. – Apuleius Jan 25 '15 at 13:53
  • 1
    Also getting it on S5 with lollipop even though there is a screen for it. Seems they have removed all settings shortcuts as theres no settings shortcut widget anymore. – Chris.D Feb 18 '15 at 00:27
  • anyone know if LG G3 use the old version of 'getRecentTask()' that don't work on android lollipop now? – alex_au Mar 24 '15 at 14:58
  • I really would like to know as well what the G3 has done, can anyone comment with a G3? – AutoM8R Apr 01 '15 at 03:50