Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select File from file manager via Intent

What I wanna do:

I wanna get the path as a String of a file, which I choose via an Android File Manager.

What I have:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent, "Open with ..."), FILE_SELECT_CODE);

This code, works nearly fine for me, but there is one problem. I can only select my file with the following apps:

enter image description here

My Question:

Does anyone have a working code for choosing any file via the Android File Manager?

like image 547
Pixel_95 Avatar asked Sep 29 '15 22:09

Pixel_95


1 Answers

You can use this:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*"); 
startActivityForResult(intent, REQUEST_CODE);

For samsung devices to open file manager use this:

Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);

For more reference checkout http://developer.android.com/guide/topics/providers/document-provider.html

like image 62
Aakash Avatar answered Oct 22 '22 08:10

Aakash