Md Azharuddin
Md Azharuddin

Reputation: 1476

Error in creating a folder using Storage Access Framework

I am using Storage Access Framework and want to create a folder (location choosed by user through file picker) but instead it is creating a file without any extension.
I am using ACTION_CREATE_DOCUMENT for this, you can check the intent call below:

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.setType("application/vnd.google-apps.folder");
intent.putExtra(Intent.EXTRA_TITLE, "CCM-Tele ICU");
startActivityForResult(intent, MAKE_DIRECTORY_REQUEST_ID);

But instead of folder it is creating this:
bin file

I have tried creating files and it works fine but unfortunately, folder is not being created.

Upvotes: 2

Views: 387

Answers (1)

Md Azharuddin
Md Azharuddin

Reputation: 1476

I solved the problem of directory creation so answering my own question maybe it will help someone in future.

The Mime type that I was using is incorrect. So change it to: DocumentsContract.Document.MIME_TYPE_DIR

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.setType(DocumentsContract.Document.MIME_TYPE_DIR);
intent.putExtra(Intent.EXTRA_TITLE, "CCM-Tele ICU");
startActivityForResult(intent, MAKE_DIRECTORY_REQUEST_ID);

But it's useless as I can't use it to store things afterwards using SAF. So it's better to use ACTION_OPEN_DOCUMENT_TREE instead

Upvotes: 1

Related Questions