1

当我们尝试在 Sprint 网络上运行的三星 Galaxy S3 (Android 4.0.4) 上查询“content://mms-sms/conversations/”时,我们遇到了以下崩溃。我们的调用代码:

    Uri uri = Uri.parse("content://mms-sms/conversations/");

    Log.e("IL", "CONTENT MIME " + context.getApplicationContext().getContentResolver().getType(uri));

    // The next call crashes...
     Cursor cursor = context.getApplicationContext().getContentResolver().query(uri, null, null, null, null);

有趣的事实是上面的日志返回

    CONTENT MIME vnd.android-dir/mms-sms

正如预期的那样。

下面的堆栈跟踪:

Caused by: java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1333)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:182)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
at android.content.ContentProviderClient.query(ContentProviderClient.java:50)
at com.ilyngo.sms.model.MessageCatalog.refresh(MessageCatalog.java:107)
at com.ilyngo.sms.model.MessageCatalog.getSharedCatalog(MessageCatalog.java:58)
at com.ilyngo.sms.model.ContactsManager.clearCaches(ContactsManager.java:31)
at com.ilyngo.sms.app.bill_test.ThreadListActivity.onResume(ThreadListActivity.java:57)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1158)
at android.app.Activity.performResume(Activity.java:4544)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2448)
... 12 more
java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1333)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:182)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
at android.content.ContentProviderClient.query(ContentProviderClient.java:50)
at com.ilyngo.sms.model.MessageCatalog.refresh(MessageCatalog.java:107)
at com.ilyngo.sms.model.MessageCatalog.getSharedCatalog(MessageCatalog.java:58)
at com.ilyngo.sms.model.ContactsManager.clearCaches(ContactsManager.java:31)
at com.ilyngo.sms.app.bill_test.ThreadListActivity.onResume(ThreadListActivity.java:57)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1158)
at android.app.Activity.performResume(Activity.java:4544)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2448)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2486)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4514)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

1

可以使用简化版本的查询来解决问题:

Uri.parse("content://mms-sms/conversations?simple=true"); 
Cursor cursor = context.getApplicationContext().getContentResolver().query(uri, null, null, null, null);

这里的关键点是 URI content://mms-sms/conversations?simple=true

于 2012-11-30T07:38:37.200 回答
0

此 ContentProvider 不接受空投影。您必须使用“*”显式提供它,以便将其传递给底层 SQL 查询语句:

final String[] proj = {"*"};
Cursor cursor = context.getApplicationContext().getContentResolver().query(uri, proj, null, null, null);

我想这是一个一般的Android问题。

检查这个问题:如何在 Android 中读取彩信数据?

于 2012-10-01T10:29:18.423 回答