6

我正在开发 SMS 应用程序,需要列出 SMS 对话。尝试使用 uri 访问内容提供者时发现问题content://mms-sms/conversations/。它在 Android 2.3 上运行良好,但在 Android 4.0.3 Samsung Galaxy Tab 2 上运行时返回错误:

 10-17 09:04:51.035: E/AndroidRuntime(22600): FATAL EXCEPTION: main
 10-17 09:04:51.035: E/AndroidRuntime(22600):
 java.lang.RuntimeException: Unable to start activity
 ComponentInfo{com.yooi/com.yooi.ui.MainActivity}:
 android.view.InflateException: Binary XML file line #6: Error
 inflating class fragment 10-17 09:04:51.035: E/AndroidRuntime(22600):
    at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.ActivityThread.access$600(ActivityThread.java:128) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.os.Handler.dispatchMessage(Handler.java:99) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.os.Looper.loop(Looper.java:137) 10-17 09:04:51.035:
 E/AndroidRuntime(22600):   at
 android.app.ActivityThread.main(ActivityThread.java:4514) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 java.lang.reflect.Method.invokeNative(Native Method) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 java.lang.reflect.Method.invoke(Method.java:511) 10-17 09:04:51.035:
 E/AndroidRuntime(22600):   at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 dalvik.system.NativeStart.main(Native Method) 10-17 09:04:51.035:
 E/AndroidRuntime(22600): Caused by: android.view.InflateException:
 Binary XML file line #6: Error inflating class fragment 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.view.LayoutInflater.rInflate(LayoutInflater.java:739) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.inflate(LayoutInflater.java:489) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.inflate(LayoutInflater.java:396) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.inflate(LayoutInflater.java:352) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.Activity.setContentView(Activity.java:1835) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 com.yooi.ui.MainActivity.onCreate(MainActivity.java:17) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.app.Activity.performCreate(Activity.java:4465) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   ... 11 more 10-17
 09:04:51.035: E/AndroidRuntime(22600): Caused by:
 java.lang.NullPointerException 10-17 09:04:51.035:
 E/AndroidRuntime(22600):   at
 android.os.Parcel.readException(Parcel.java:1334) 10-17 09:04:51.035:
 E/AndroidRuntime(22600):   at
 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.content.ContentResolver.query(ContentResolver.java:311) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 com.yooi.ui.SmsThreadListActivity.getThreadListCursor(SmsThreadListActivity.java:146)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 com.yooi.ui.SmsThreadListActivity.onCreateView(SmsThreadListActivity.java:95)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:806)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1010)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1108)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   at
 android.app.Activity.onCreateView(Activity.java:4243) 10-17
 09:04:51.035: E/AndroidRuntime(22600):     at
 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
 10-17 09:04:51.035: E/AndroidRuntime(22600):   ... 21 more

我花了很多时间在谷歌上搜索它,但仍然没有找到答案。任何知道的人请帮助我,我被这个烦人的问题困住了:(

4

1 回答 1

5

可以通过此查询检索对话列表:

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:40:34.997 回答