2013-10-05 79 views
0

我試圖打開screenshots照片文件夾。android.content.ActivityNotFoundException:找不到處理意圖的活動{act = android.intent.action.GET_CONTENT

 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)); 
      }    

我有此權限的清單:

<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): [email protected] > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error 
10-05 22:17:29.950: E/Watchdog(2282): [email protected] 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的作品,但我更喜歡默認的照片庫中查看

我看了一下這些文檔中,但並沒有完全理解它們之間的區別。有人能清楚這一點嗎?

回答

2

首先,setData()清除了您的setType() IIRC。當你真的需要兩個(提示:不在這裏)時,把它們和setDataAndType()一起設置。

二,ACTION_GET_CONTENT是供選擇的類型,而不是位置。引用the documentation for ACTION_GET_CONTENT

注意,沒有URI在意圖提供的,因爲有在哪裏返回的數據最初來源於

因此沒有任何限制,你將需要刪除您setData()通話和公正使用setType()。但是,這不會從該文件夾中選擇。

ACTION_PICK是您指定要從中選擇的集合的位置,而不是類型。但是,我們無法保證設備上會有支持ACTION_PICK的應用程序,可用於file://Uri

我建議你直接在應用程序中實現UI。

相關問題