Android intent Android RuntimeException:传递结果ResultInfo失败
因此,在用户选择联系人后,我将执行以下代码以获取联系人号码:Android intent Android RuntimeException:传递结果ResultInfo失败,android-intent,android-4.4-kitkat,android-cursor,Android Intent,Android 4.4 Kitkat,Android Cursor,因此,在用户选择联系人后,我将执行以下代码以获取联系人号码: public void openSmsWindowToContactNumber(Intent data, String smsBody) { // Get the URI that points to the selected contact Uri contactUri = data.getData(); // We only need the NUMBER column, bec
public void openSmsWindowToContactNumber(Intent data, String smsBody) {
// Get the URI that points to the selected contact
Uri contactUri = data.getData();
// We only need the NUMBER column, because there will be only one row in the result
String[] projection = {Phone.NUMBER};
// Perform the query on the contact to get the NUMBER column
// We don't need a selection or sort order (there's only one result for the given URI)
// CAUTION: The query() method should be called from a separate thread to avoid blocking
// your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
// Consider using CursorLoader to perform the query.
Cursor cursor = BaseActivity.this.getContentResolver()
.query(contactUri, projection, null, null, null);
cursor.moveToFirst();
int column = cursor.getColumnIndex(Phone.NUMBER);
String number = cursor.getString(column);
Intent smsIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + number));
smsIntent.putExtra("sms_body", smsBody);
startActivity(smsIntent);
}
在设备Lenovo A916(A916)OS:Android 4.4上运行时,我遇到以下错误:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=75502, result=-1, data=Intent { dat=content://com.android.contacts/data/240 flg=0x1 }} to activity {com.sm.proba/com.sm.proba.ClassPage}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3553)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3596)
at android.app.ActivityThread.access$1300(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at
游标将为空,未找到联系人数据。我开始通过以下方式选择联系人意向:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, REQUEST_CODE_PICK_CONTACTS);
有人知道如何解决这个问题吗?有没有找到解决方案?没有,我没有找到解决方案。不过,我想光标是错的,因为需要两个光标,所以接收电话号码信息更复杂。你解决了这个问题吗?还在找,昨天刚拿到。我会让你知道我是否能修好它。通常我认为您在AndroidManifest.xml中没有读取联系人的权限