android.content.ActivityNotFoundException:找不到处理Intent的Activity {act = android.intent.action.GET_CONTENT

时间:2013-10-05 19:18:27

标签: java android eclipse android-intent

我正在尝试打开screenshots照片文件夹。

        private void Try3()
        {
            File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/Screenshots");
            Log.d("File path ", dir.getPath());
            String dirPath=dir.getAbsolutePath();
            if(dir.exists() && dir.isDirectory()) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
                intent.setType("image/*");
                intent.setData(Uri.fromFile(dir));

                Log.d("b4performSpecificCrop_startActivityForResult::", Integer.toString(3));
                startActivityForResult(intent, 3);
                Log.d("afterperformSpecificCrop_startActivityForResult::", Integer.toString(3));
            }             

我在Manifest中有这个权限:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

从logCat获取:

10-05 22:17:26.790: E/AndroidRuntime(28347): FATAL EXCEPTION: main
10-05 22:17:26.790: E/AndroidRuntime(28347): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT dat=file:///storage/sdcard0/Pictures/Screenshots }
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1580)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.Activity.startActivityForResult(Activity.java:3446)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.Activity.startActivityForResult(Activity.java:3407)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at de.vogella.android.todos.TodoDetailActivity$1.Try3(TodoDetailActivity.java:149)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at de.vogella.android.todos.TodoDetailActivity$1.onClick(TodoDetailActivity.java:132)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.view.View.performClick(View.java:4223)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.view.View$PerformClick.run(View.java:17275)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.os.Handler.handleCallback(Handler.java:615)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.os.Looper.loop(Looper.java:137)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at android.app.ActivityThread.main(ActivityThread.java:4898)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at java.lang.reflect.Method.invokeNative(Native Method)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at java.lang.reflect.Method.invoke(Method.java:511)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
10-05 22:17:26.790: E/AndroidRuntime(28347):    at dalvik.system.NativeStart.main(Native Method)
10-05 22:17:26.815: E/android.os.Debug(2282): !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error
10-05 22:17:29.950: E/Watchdog(2282): !@Sync 36
10-05 22:17:31.460: E/WifiP2pStateTracker(2282): getNetworkInfo : NetworkInfo: type: WIFI_P2P[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
10-05 22:17:32.890: E/Sensors(2282): Gyro old sensor_state 75, new sensor_state : 73 en : 0
10-05 22:17:32.895: E/Sensors(2282): Pressure old sensor_state 73, new sensor_state : 65 en : 0
10-05 22:17:38.545: E/MtpService(2826): In MTPAPP onReceive:android.intent.action.BATTERY_CHANGED
10-05 22:17:38.550: E/MtpService(2826): battPlugged Type : 2

更新

ACTION_VIEW不起作用

ACTION_GET_CONTENT不起作用

ACTION_PICK有效,但我更喜欢默认照片库视图

我在文档中已经阅读过这些内容,但并未完全理解它们之间的区别。有人可以解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

首先,setData()消灭了setType() IIRC。当你确实需要两者时(提示:不在这里),将它们与setDataAndType()一起设置。

其次,ACTION_GET_CONTENT用于按类型选择,而不是位置。引用the documentation for ACTION_GET_CONTENT

  

请注意,intent中没有提供URI,因为对返回的数据最初来自何处没有限制

因此,您需要移除setData()来电并使用setType()。但是,这不会从该文件夹中选择。

ACTION_PICK是指定要从中挑选的集合的位置,而不是类型。但是,我们无法保证设备上会有ACTION_PICK file://支持Uri的应用。

我建议您直接在应用程序中实现UI。