0
我在谷歌播放的崩溃报告中出现错误,我正在寻找联系人列表中的联系人,以便知道是否必须创建它或者它是否已存在,但它给我java.lang.SecurityException异常在Android 7.0设备,这是我的代码:搜索联系人上的java.lang.SecurityException
public boolean contactExists() {
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(RegisterActivity.this,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(RegisterActivity.this,
Manifest.permission.READ_CONTACTS)) {
showMessageOKCancel("Necesitas permisos para guardar nuestro contácto en tu teléfono y poder enviarnos mensajes");
return false;
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
if (Bellisima_number != null) {
Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(Bellisima_number));
String[] mPhoneNumberProjection = { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup.DISPLAY_NAME };
Cursor cur = this.getContentResolver().query(lookupUri, mPhoneNumberProjection, null, null, null);
try {
if (cur.moveToFirst()) {
return true;
}
} finally {
if (cur != null)
cur.close();
}
return false;
} else {
return false;
}
}
}
return false;
}// contactExists
我有接触权限在我的清单
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
我正在寻找,但我无法理解这个错误,我希望有人能帮助我。
编辑: 这是我在谷歌跟踪播放
java.lang.SecurityException:
at android.os.Parcel.readException (Parcel.java:1683)
at android.os.Parcel.readException (Parcel.java:1636)
at android.app.ActivityManagerProxy.getContentProvider (ActivityManagerNative.java:4263)
at android.app.ActivityThread.acquireProvider (ActivityThread.java:5475)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider (ContextImpl.java:2239)
at android.content.ContentResolver.acquireUnstableProvider (ContentResolver.java:1515)
at android.content.ContentResolver.query (ContentResolver.java:514)
at android.content.ContentResolver.query (ContentResolver.java:472)
at co.bellisima.bellisimaco.RegisterActivity.contactExists (RegisterActivity.java:318)
at co.bellisima.bellisimaco.RegisterActivity.createUser (RegisterActivity.java:209)
at co.bellisima.bellisimaco.RegisterActivity$1.onComplete (RegisterActivity.java:149)
at com.google.android.gms.tasks.zzc$1.run (Unknown Source)
at android.os.Handler.handleCallback (Handler.java:751)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6123)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:757)
请编辑问题并发布整个Java堆栈跟踪。另外,请确保您已设置[运行时权限](https://developer.android.com/training/permissions/requesting.html),因为“READ_CONTACTS”和“WRITE_CONTACTS”都是“危险”权限。 – CommonsWare
只需要清楚......第一行('java.lang.SecurityException:')中的':'后面没有任何内容,接下来是'at android.os.Parcel.readException'处?通常,一个'SecurityException'提供了关于到底出错的更多细节。 – CommonsWare
是的,我只是复制和粘贴就像它 –