我从我的一个用户那里得到了这个错误,我不知道如何修复它…
java.lang.IollegalArgumentExceptionDatabaseUtils.readExceptionFromParcel()
java.lang.IllegalArgumentException: URI: content://com.android.contacts/phone_lookup/, calling user: com.piroja.contactpicker, calling package:com.piroja.contactpicker at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
at android.content.ContentResolver.query(ContentResolver.java:245)
at com.piroja.contactpicker.ContactPicker.contactExists(ContactPicker.java:257)
at com.piroja.contactpicker.ContactPicker$6$1.onClick(ContactPicker.java:138)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
at dalvik.system.NativeStart.main(Native Method)
这是我正在调用的contactExists函数,(我认为)它导致了强制关闭:
public boolean contactExists(Context context, String number) {
try {
Uri lookupUri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri
.encode(number));
String[] mPhoneNumberProjection = { Phone._ID, Phone.NUMBER,
Phone.DISPLAY_NAME };
Cursor cur = context.getContentResolver().query(lookupUri,
mPhoneNumberProjection, null, null, null);
try {
if (cur.moveToFirst()) {
return true;
}
} finally {
if (cur != null)
cur.close();
}
} catch (IllegalArgumentException iae) {
return false;
}
return false;
}
我还尝试将Phone.CONTENT_FILTER_URI更改为PhoneRookup.CONTENT_FILTER _URI,但没有更改任何内容。。。有人知道线索吗?
电话查询URI有问题。从异常文本来看,它似乎缺少电话号码。你确定数字不是空的吗?
这可能发生在掩码数字中。http://code.google.com/p/gtalksms/issues/detail?id=27
我不知道是否还有人需要这个答案,但我一直在尝试,直到我得到它。问题是,有时,当你扩展PhoneStateListener
类时,或者当传递最后一个传入号码时,传入号码是null
。我把我的代码改成了这个,它运行得很好
@Override
public void onReceive(final Context context, final Intent intent) {
Log.d("APP", "ACTION:" + intent.getAction());
final String stringExtra = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (TelephonyManager.EXTRA_STATE_RINGING.equals(stringExtra)) {
final String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.d("APP", "incoming,ringing:" + incomingNumber);
} else if (stringExtra.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
final String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.d("APP", "hanged" + incomingNumber );
} else if (stringExtra.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
final String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.d("APP", "answered" + incomingNumber );
}
}
…这个解决方案就在这里。