2
我想獲取手機相冊的相冊列表。 我試過碼位它不工作Android中的圖庫相冊列表
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView view = new TextView(this);
Uri uriListURI = Uri.parse("MediaStore.Files.CONTENT_URI");
Cursor cur = getContentResolver().query(uriListURI, null, null, null,null);
String list = "";
while (cur.moveToNext()) {
list += cur.getString((cur.getColumnIndex("MediaStore.Files._ID")));
}
view.setText(list);
setContentView(view);
}}
我得到這些錯誤
E/AndroidRuntime(10572): FATAL EXCEPTION: main
E/AndroidRuntime(10572): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sms/com.example.sms.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime(10572): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2313)
E/AndroidRuntime(10572): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
E/AndroidRuntime(10572): at android.app.ActivityThread.access$600(ActivityThread.java:156)
E/AndroidRuntime(10572): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
E/AndroidRuntime(10572): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(10572): at android.os.Looper.loop(Looper.java:153)
E/AndroidRuntime(10572): at android.app.ActivityThread.main(ActivityThread.java:5336)
E/AndroidRuntime(10572): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(10572): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(10572): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
E/AndroidRuntime(10572): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
E/AndroidRuntime(10572): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(10572): Caused by: java.lang.NullPointerException
E/AndroidRuntime(10572): at com.example.sms.MainActivity.onCreate(MainActivity.java:35)
E/AndroidRuntime(10572): at android.app.Activity.performCreate(Activity.java:5122)
E/AndroidRuntime(10572): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
E/AndroidRuntime(10572): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2277)
: E/AndroidRuntime(10572): ... 11 more
我用同樣的方式來獲取短信和它的工作
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView view = new TextView(this);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
String sms = "";
while (cur.moveToNext()) {
sms += "From :" + cur.getString((cur.getColumnIndex("address")));
}
view.setText(sms);
setContentView(view);}}
設置一些佈局的setContentView(佈局);並添加TextView –
我編輯我的帖子,所以你可以看到沒有問題的佈局 – Marya
我們正確的路上。但對於'content:// sms/inbox',您在'manifest.xml'中添加了許可'SMS READ'並且 –