In Android 4.4, Apps from Play Store can write only to it's App specific directory( eg:/storage/extSdCar/Android/data/com.example.myapp/ ) and apps are not allowed to write other than this directory in micro SD card. So I am exploring the new SAF API to check whether I can use SAF to write to micro SD card other than the app specific directory.
I have implemented SAF by creating a sample provider and client app. In my provider, I tried to show the entire content of SD card by implementing the following code in queryRoots:
row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(new File("/storage/extSdCard")));
row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_RECENTS | Root.FLAG_SUPPORTS_SEARCH);
I have created the following intent in my client and I am able to browse the entire content of SD card through my provider from System UI of SAF.
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TITLE, "test.txt");
startActivityForResult(intent, WRITE_REQUEST_CODE);
When I click the save button,I am getting a Toast error "Failed to save document".But when I navigate to the App specific directory(/storage/extSdCar/Android/data/com.example.myprovider/) of my provider in System UI, I am able to save the document. Also there is NO intent such as Intent.CATEGORY_WRITABLE so that I can get only documents that can be edited. Please help me on the below points:
1.It seems that even if we use SAF, still WRITE restriction on micro SD card remains the same. Is this correct?
2.Is there any way that I can create or delete or modify already available files outside my App specific directory in micro SD card?
3.Who decides the FLAG_SUPPORTS_WRITE flag for normal user files such as Photos, Videos, Music, documents, etc ?