问题描述
您可能知道,自启动Android 5以来,访问设备的最新任务(使用情况统计信息)要求用户手动启用此功能(设置->安全->使用访问权限).
As you might know, since Android 5 was launched, accessing the recent tasks (usage stats) of your device requires the user to enable this feature manually (Settings->Security->Usage Access).
我的应用检查设备是否使用Android 5,如果是,则为用户提供打开设置屏幕以启用使用权限的可能性:
My app checks if the device uses Android 5, and if so, then it offers the user the possibility of opening the settings screen for enabling usage access:
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivityForResult(intent, 12345);
当我尝试在运行Android 5的三星设备中执行此操作时,问题就来了...当执行上面显示的行时,我收到了此错误:
The problem comes when I try to do this in a Samsung device running Android 5... I got this error when the line shown above is executed:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.USAGE_ACCESS_SETTINGS }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1801)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1499)
at android.app.Activity.startActivityForResult(Activity.java:3913)
似乎尚未实现Settings.ACTION_USAGE_ACCESS_SETTINGS操作,这很奇怪,因为如果转到设置",则有启用该应用程序访问此使用情况统计信息的选项...
It seems that the Settings.ACTION_USAGE_ACCESS_SETTINGS action has not been implemented, which is weird because if you go to Settings the option to enable the app to access this usage stats is there...
是否有针对这种情况解决此问题的想法?
Any idea of how to fix this problem for this specific case?
推荐答案
抱歉,我的答复很晚,希望您找到了一个好的解决方案,但如果没有找到,或者对于有此问题的其他人,
Sorry for the late reply, I hope you have found a good solution, but if not or for other people who have this problem,
在某些三星型号中似乎存在此错误,为避免您的应用崩溃,也许您可以检查自己的意图是否可以解决
this bug seems to exist in some Samsung models, to avoid the crash of your app, maybe you can check if your intent can be handled
PackageManager packageManager = getActivity().getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent);
} else {
Toast.makeText(getBaseContext(), "Please open settings, your model can't be forced
to open it", Toast.LENGTH_LONG).show();
}
这篇关于适用于Android 5 Samsung设备的Android使用访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!