0

I am using following intent to select any file from my device but its only selecting file for Samsung Tablet not for any other device.

Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);
nicopico
  • 3,606
  • 1
  • 28
  • 30
Usman Ahmed
  • 39
  • 3
  • 9

1 Answers1

1

According to the documentation, you should use an ACTION_PICK intent with the startActivityForResult() method:

final int ACTION_PICK_RESULT = 0;

Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("*/*");
startActivityForResult(intent, ACTION_PICK_RESULT);

You can then retrieve the file in the onActivityResult() method of your activity.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent returnIntent) {
    if (resultCode == RESULT_OK) {
        Uri returnUri = returnIntent.getData();
        try {
            ParcelFileDescriptor pfd = getContentResolver()
                    .openFileDescriptor(returnUri, "r");
            FileDescriptor fd = pfd.getFileDescriptor();

            // TODO Do stuff with the file
        } 
        catch (FileNotFoundException e) {
            Log.e("MainActivity", "File not found.");
        }
    }
}

See this page for more information: Requesting a Shared File

nicopico
  • 3,606
  • 1
  • 28
  • 30