簡體   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