我四处寻找,但无法找到解决方案。我刚刚更新了我的应用程序以定位Android API 25.因此,我不得不更新权限处理。我的应用需要以下权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
我添加了检查/请求权限的所有代码,并在两部不同的手机上对其进行了测试。然而,一些用户正在崩溃:
java.lang.RuntimeException:
at android.os.AsyncTask$3.done (AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:354)
at java.util.concurrent.FutureTask.setException (FutureTask.java:223)
at java.util.concurrent.FutureTask.run (FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:607)
at java.lang.Thread.run (Thread.java:762)
Caused by: java.lang.SecurityException:
at android.os.Parcel.readException (Parcel.java:1693)
at android.os.Parcel.readException (Parcel.java:1646)
at android.app.ActivityManagerProxy.getContentProvider (ActivityManagerNative.java:4912)
at android.app.ActivityThread.acquireProvider (ActivityThread.java:6043)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider (ContextImpl.java:2474)
at android.content.ContentResolver.acquireUnstableProvider (ContentResolver.java:1521)
at android.content.ContentResolver.query (ContentResolver.java:520)
at android.content.CursorLoader.loadInBackground (CursorLoader.java:64)
at android.content.CursorLoader.loadInBackground (CursorLoader.java:56)
at android.content.AsyncTaskLoader.onLoadInBackground (AsyncTaskLoader.java:312)
at android.content.AsyncTaskLoader$LoadTask.doInBackground (AsyncTaskLoader.java:69)
at android.content.AsyncTaskLoader$LoadTask.doInBackground (AsyncTaskLoader.java:66)
at android.os.AsyncTask$2.call (AsyncTask.java:304)
at java.util.concurrent.FutureTask.run (FutureTask.java:237)
正如您所看到的,我收到的安全例外没有任何细节。此外,堆栈跟踪显示它根本不是来自我的代码。
有谁能告诉我如何解决这个问题?我读错了堆栈跟踪吗?
编辑:问题必须源于尝试从联系人构建用户电子邮件列表。这是代码:
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new CursorLoader(this,
// Retrieve data rows for the device user's 'profile' contact.
Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
// Select only email addresses.
ContactsContract.Contacts.Data.MIMETYPE +
" = ?", new String[]{ContactsContract.CommonDataKinds.Email
.CONTENT_ITEM_TYPE},
// Show primary email addresses first. Note that there won't be
// a primary email address if the user hasn't specified one.
ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
}
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
List<String> emails = new ArrayList<>();
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
emails.add(cursor.getString(ProfileQuery.ADDRESS));
cursor.moveToNext();
}
addEmailsToAutoComplete(emails);
}
答案 0 :(得分:1)
我发现了发生了什么。在我的代码中,有一个更加模糊的地方称这个:
getLoaderManager().initLoader(0, null, this);
解决方案是在获取用户联系人数据之前进行正常的权限检查。
事实证明,Google Play控制台不会在其堆栈跟踪中显示安全异常详细信息。您只能在调试模式下查看实际所需的权限。