Question

I am trying to open the download's folder programmatically. But, I keep getting ActivityNotFoundException. I have seen various questions on this on StackOverflow, tried most of them, but nothing worked till now. Here is my code below

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

AndroidManifest.xml - related code

<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>

I think I have set the required things in manifest too, but, I still keep getting the Exception.

I have a download button in VideoWebViewActivity, when clicked, downloads a file and then has to open the download folder on the device. Is setting, category to DEFAULT as above, correct? or should I be using a new activity(I don't really need any other activity, so should I be using a dummy activity? Doesn't sound right...)?

Here is my 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)
Was it helpful?

Solution

I haven't yet figured it out, but, for now, I am directly opening the file that I downloaded using the below code...

        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 = the path of the FILE(not directory) that you want to open.

Will update the answer, if I get to open the directory successfully.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top