gpt4 book ai didi

安卓 P : UsageStatsManager getAppStandbyBucket

转载 作者:行者123 更新时间:2023-12-05 00:00:08 24 4
gpt4 key购买 nike

我想显示 current bucket我的应用程序在 Android P beta 下的设备上。因此,我尝试像这样使用 UsageStatsManager 类:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (Build.VERSION.SDK_INT >= 28) {
UsageStatsManager usageStatsManager = (UsageStatsManager) getSystemService(USAGE_STATS_SERVICE);
if (usageStatsManager != null) {
Log.d(TAG, "getAppStandbyBucket():" + usageStatsManager.getAppStandbyBucket());
}
}
}

我的 list 拥有 android.permission.PACKAGE_USAGE_STATS 权限:

<uses-permission 
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />

但是当我启动我的应用程序时遇到崩溃:

07-24 10:23:39.061 26967-26967/com.app.bucket E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.bucket, PID: 26967
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.bucket/com.app.bucket.MainActivity}: java.lang.SecurityException: MATCH_ANY_USER flag requires INTERACT_ACROSS_USERS permission at com.android.server.pm.PackageManagerService.getPackageUid:4343 com.android.server.pm.PackageManagerService$PackageManagerInternalImpl.getPackageUid:23964 com.android.server.usage.UsageStatsService$BinderService.getAppStandbyBucket:927 android.app.usage.IUsageStatsManager$Stub.onTransact:274 android.os.Binder.execTransact:731 : Neither user 10118 nor current process has android.permission.INTERACT_ACROSS_USERS.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.SecurityException: MATCH_ANY_USER flag requires INTERACT_ACROSS_USERS permission at com.android.server.pm.PackageManagerService.getPackageUid:4343 com.android.server.pm.PackageManagerService$PackageManagerInternalImpl.getPackageUid:23964 com.android.server.usage.UsageStatsService$BinderService.getAppStandbyBucket:927 android.app.usage.IUsageStatsManager$Stub.onTransact:274 android.os.Binder.execTransact:731 : Neither user 10118 nor current process has android.permission.INTERACT_ACROSS_USERS.
at android.os.Parcel.createException(Parcel.java:1942)
at android.os.Parcel.readException(Parcel.java:1910)
at android.os.Parcel.readException(Parcel.java:1860)
at android.app.usage.IUsageStatsManager$Stub$Proxy.getAppStandbyBucket(IUsageStatsManager.java:658)
at android.app.usage.UsageStatsManager.getAppStandbyBucket(UsageStatsManager.java:479)
at com.app.bucket.MainActivity.onCreate(MainActivity.java:60)

似乎我错过了一个权限,但即使我添加了以下权限:

  <uses-permission
android:name="android.permission.INTERACT_ACROSS_USERS"
tools:ignore="ProtectedPermissions" />

我仍然遇到同样的崩溃。我在想,也许我错过了权限的运行时调用,但就像 documentation规定:

NOTE: Most methods on this API require the permission android.permission.PACKAGE_USAGE_STATS. However, declaring the permission implies intention to use the API and the user of the device still needs to grant permission through the Settings application. See Settings.ACTION_USAGE_ACCESS_SETTINGS. Methods which only return the information for the calling package do not require this permission. E.g. getAppStandbyBucket() and queryEventsForSelf(long, long).

没必要。即使知道我尝试使用运行时权限,但我仍然遇到崩溃。如果有人看到缺少的东西,我将非常感谢您的帮助。

最佳答案

我认为这是一个错误。问题跟踪器中有一个 Unresolved 问题:https://issuetracker.google.com/issues/111102580 .

关于安卓 P : UsageStatsManager getAppStandbyBucket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51494512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com