2014-03-28 41 views
1

我試圖以編程方式打開下載的文件夾。但是,我不斷收到ActivityNotFoundException。我在StackOverflow上看到過關於這個問題的各種問題,嘗試了其中的大部分,但直到現在還沒有任何工作。這裏是我的代碼如下以編程方式打開文件夾 - ActivityNotFoundException Android

Intent intent = new Intent(Intent.ACTION_VIEW); 
       intent.setData(Uri.parse(downloadDirectoryPath)); 
       startActivity(intent); 

AndroidManifest.xml中 - 相關的代碼

<activity 
    android:name="com.xx.xxx.videowebview.VideoWebViewActivity" 
    android:configChanges="orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
    android:hardwareAccelerated="true" 
    android:label="@string/app_name" 
    android:theme="@style/custom_theme" > 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW" /> 

     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
</activity> 

我想我已經設置清單中所需要的東西太多,但是,我仍然不斷收到異常。

我有一個下載按鈕VideoWebViewActivity,點擊後,下載一個文件,然後必須打開設備上的download文件夾。設置,類別爲默認如上,是否正確?或者我應該使用新的活動(我不需要任何其他活動,所以我應該使用虛擬活動?聽起來不正確...)?

這是我的logcat ...

03-28 15:17:37.349: E/AndroidRuntime(15791): FATAL EXCEPTION: main 
03-28 15:17:37.349: E/AndroidRuntime(15791): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/download/ } 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.Activity.startActivityForResult(Activity.java:2827) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.Activity.startActivity(Activity.java:2933) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at com.xx.xxx.videowebview.VideoWebViewActivity$DownloadFile.onPostExecute(VideoWebViewActivity.java:442) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at com.xx.xxx.videowebview.VideoWebViewActivity$DownloadFile.onPostExecute(VideoWebViewActivity.java:1) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.AsyncTask.finish(AsyncTask.java:417) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.AsyncTask.access$300(AsyncTask.java:127) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.Looper.loop(Looper.java:130) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.ActivityThread.main(ActivityThread.java:3687) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at java.lang.reflect.Method.invokeNative(Native Method) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at java.lang.reflect.Method.invoke(Method.java:507) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) 
03-28 15:17:37.349: E/AndroidRuntime(15791): at dalvik.system.NativeStart.main(Native Method) 

回答

0

我還沒有想通了,但是,現在,我直接打開,我用下面的代碼下載的文件...

 File file = new File(path); 
     Uri uri_path = Uri.fromFile(file); 
     String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension 
       (MimeTypeMap.getFileExtensionFromUrl(path)); 


     Intent intent = new Intent(android.content.Intent.ACTION_VIEW); 
     intent.setType(mimeType); 
     intent.setDataAndType(uri_path, mimeType); 
     startActivity(intent); 

path =要打開的FILE(不是目錄)的路徑。

如果我能成功打開目錄,將更新答案。

+0

您是否找到解決方案?我嘗試了很多類型:資源/文件夾等,但沒有人工作,如果設備沒有SD卡 – 2015-12-13 21:59:29

相關問題