繁体   English   中英

Android崩溃,权限为UPDATE_DEVICE_STATS

[英]Android crash with permission UPDATE_DEVICE_STATS

我在Crashlytics中收到了android.permission.UPDATE_DEVICE_STATS权限导致的崩溃。 我不需要我的应用程序中的此权限,因为我不需要它。 我无法重现此问题。 当应用尝试在ContentResolver中调用查询方法时,发生崩溃。

也许有人碰到了这个问题,并且知道原因或如何解决。 它发生在银河J5(2016)

Fatal Exception: java.lang.RuntimeException: Unable to create application com.myapp.App: java.lang.SecurityException: uid 10166 does not have android.permission.UPDATE_DEVICE_STATS.
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6326)
       at android.app.ActivityThread.access$1800(ActivityThread.java:223)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:158)
       at android.app.ActivityThread.main(ActivityThread.java:7231)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by java.lang.SecurityException: uid 10166 does not have android.permission.UPDATE_DEVICE_STATS.
       at android.os.Parcel.readException(Parcel.java:1620)
       at android.os.Parcel.readException(Parcel.java:1573)
       at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4240)
       at android.app.ActivityThread.acquireProvider(ActivityThread.java:6394)
       at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2380)
       at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1521)
       at android.content.ContentResolver.query(ContentResolver.java:486)
       at android.content.ContentResolver.query(ContentResolver.java:445)
       at com.myapp.wrapper.AppSettingWrapper.getDeviceId(AppSettingWrapper.java:103)
       at com.myapp.wrapper.AppSettingWrapper.setNewDeviceId(AppSettingWrapper.java:160)
       at com.myapp.App.onCreate(Mail2WorldApplication.java:70)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6323)
       at android.app.ActivityThread.access$1800(ActivityThread.java:223)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:158)
       at android.app.ActivityThread.main(ActivityThread.java:7231)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

编辑: getDeviceId方法的代码

public static String getDeviceId(Context context){
    boolean isNotEnd = true;
    String deviceId = "";
    while (isNotEnd) { // I guess this loop is needed to refetch data, if the app wasn't able to fetch getDeviceId from the first time 
        isNotEnd = false;
        Uri uriDeviceId = AppSettingsContentProvider.DEVICE_ID_CONTENT_URI;
        Cursor cursor = context.getContentResolver().query(uriDeviceId, null, null, null, null);
        if(cursor != null){
            try {
                if(cursor.moveToFirst()) {
                    deviceId = cursor.getString(0);
                }
            } catch (CursorIndexOutOfBoundsException e){
                isNotEnd = true;
            }finally {
                cursor.close();
            }
        }else{
            isNotEnd = true;
        }
    }
    return deviceId;
}

对于大于23的api,您需要添加运行时权限。

1)检查SDK的最低版本应大于15。

2)sdk的最大版本应大于23或23。

3)每次访问外部存储设备或其他任何东西时,都需要调用运行时权限。

4)请向本网站寻求运行时权限http://www.truiton.com/2016/04/obtaining-runtime-permissions-android-marshmallow-6-0/

https://www.sitepoint.com/requesting-runtime-permissions-in-android-m-and-n/

http://www.journaldev.com/10409/android-handling-runtime-permissions-example

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM