我四处寻找这个,但找不到我的案子的解决方案。我刚刚更新了我的应用程序以针对 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);
}