1

I have found a following code to open a specific directory:

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(StaticMember.APP_DIR);
intent.setDataAndType(uri, "resource/folder");
context.startActivity(intent);

But now I am facing an issue that it works only if ES File Explorer installed on your device, others file manager apps unable to detect.

How to resolve this issue?

Faisal Shaikh
  • 3,900
  • 5
  • 40
  • 77

1 Answers1

0

First, resource/folder is not an official MIME type.

Second, ACTION_VIEW is for viewing a piece of content. A directory is not a piece of content, from Android's standpoint.

There is no requirement for any Android device to have any activity capable of viewing the contents of a directory. There are no official standards for what Intent structure would request such an activity. There may be some conventions among file manager developers (e.g., whatever the heck resource/folder is supposed to be), but there is no requirement for all file managers to offer such an activity or for a user to have installed such a file manager.

So, you resolve the issue by either:

  • Deleting the code and eliminating the feature, or

  • Using PackageManager and queryIntentActivities() to see whether there is an activity that handles your Intent, failing gracefully if there is none

  • Catching the ActivityNotFoundException and failing gracefully if one is thrown

  • Do not attempt to rely upon third-party apps for browsing a directory, and implement your own UI for that, perhaps using existing third-party libraries for that

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I know, I can check whether there is any app to handle this kind of MIME type. the main issue is that I want to open a specific folder. – Faisal Shaikh Oct 29 '16 at 15:40
  • @FaisalShaikh: Then do not rely upon third-party apps for browsing your specific folder, and implement your own UI. – CommonsWare Oct 29 '16 at 15:46
  • Building something from scratch which is already exist is not a good idea. – Faisal Shaikh Oct 29 '16 at 15:50
  • @FaisalShaikh: It does not exist on all devices. Are you planning on forcing users to install some specific file manager, just to be able to use your app? – CommonsWare Oct 29 '16 at 15:53
  • It really sounds weird that we can not perform such a small thing in Android app. – Faisal Shaikh Oct 29 '16 at 17:19
  • @FaisalShaikh: I am not aware that you can do this in iOS either, as it has even less of a notion of "files" than Android does. Operating systems overall are trending towards trying to hide details of filesystems from users. The closest thing that Android has to this that is standard is [the Storage Access Framework](https://developer.android.com/guide/topics/providers/document-provider.html), which is only on Android 4.4+ and does not meet your requirements, since it does not deal directly with filesystem paths. – CommonsWare Oct 29 '16 at 17:29