Shruthi Nayak
Shruthi Nayak

Reputation: 43

Zip file intent chooser returns (data=null) onActivityResult

I need to open a file chooser, let the user choose a zip file. After the user chooses the zip file, onActivityResult returns data=null. I'm not sure what am I doing wrong.

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("application/zip");
        startActivityForResult(intent, SELECT_ZIP_FILE);

I tried looking for other questions and found this as one of the solution. This did not work either.

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      intent.addCategory(Intent.CATEGORY_OPENABLE);
      intent.setType("*/*");
      String[] mimetypes = {"application/zip", "text/plain"};
      intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
    } else {
      intent.setType("application/zip");
    }
    startActivityForResult(intent, SELECT_ZIP_FILE);

Any help on this is appreciated.

Note: If I use setType("*/*") without mentioning the MIME_TYPE, I'm able to open any file but not a zip file. I have appropriate permissions mentioned in my Manifest.

Upvotes: 1

Views: 622

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007321

If an ACTION_GET_CONTENT request returns RESULT_OK to onActivityResult(), and you do not get a Uri to the chosen content, there is a bug in whatever handled the ACTION_GET_CONTENT request. Unfortunately, there is little that you can do about this, other than let the user know that they chose a buggy app.

Upvotes: 1

Related Questions