0

I am following this tutorial, I am testing it on emulator, when I run this project and click on the button it is crashing and giving me the following errors

07-27 06:33:30.324: E/AndroidRuntime(10972): FATAL EXCEPTION: main
07-27 06:33:30.324: E/AndroidRuntime(10972): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT typ=file/ * }
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.app.Activity.startActivityForResult(Activity.java:2817)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at com.exercise.AndroidPick_a_File.AndroidPick_a_File$1.onClick(AndroidPick_a_File.java:35)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.view.View.performClick(View.java:2408)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.view.View$PerformClick.run(View.java:8816)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.os.Handler.handleCallback(Handler.java:587)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.os.Looper.loop(Looper.java:123)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at android.app.ActivityThread.main(ActivityThread.java:4627)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at java.lang.reflect.Method.invokeNative(Native Method)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at java.lang.reflect.Method.invoke(Method.java:521)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-27 06:33:30.324: E/AndroidRuntime(10972):    at dalvik.system.NativeStart.main(Native Method)

I want to handle this error, please help me in handling this error.

Muaz Usmani
  • 1,298
  • 6
  • 26
  • 48
  • 1
    You need to show the code you're using. Just providing the tutorial is not enough for us. – Cat Jul 27 '12 at 00:48
  • I just only wrote this tutorial yet, nothing else I wrote yet. I just copied and pasted it there nothing I changed – Muaz Usmani Jul 27 '12 at 00:53

2 Answers2

5

You have this error because you have not file explorer application on emulator.

If you want to test if file explorer is installed :

final PackageManager packageManager = getActivity().getPackageManager();
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
intent.setType("file/*");
List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                                PackageManager.GET_ACTIVITIES);

if (list.size() > 0) {
    //app installed
} else {
    //no app
}
Vitaly Zinchenko
  • 4,871
  • 5
  • 36
  • 52
SteveR
  • 2,496
  • 1
  • 24
  • 23
0

As seen in a similar question(https://stackoverflow.com/a/34181925/4098711). Assuming you are in an activity (otherwise replace this by a method returning your current activity) :

final PackageManager packageManager = this.getPackageManager();
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
ComponentName testedActivity = intent.resolveActivity(getPackageManager());
if (testedActivity != null) {
    startActivityForResult(intent,IMPORT_FILE_REQ_CODE);
} else {
    Toast.makeText(this,"No file explorer available",Toast.LENGTH_LONG).show();
}
Community
  • 1
  • 1
L2M
  • 51
  • 4