Interaction between Android Q Private Directory and Public Directory Files (Read, Copy, Save, etc.) - Pittkai

Android Q is about to launch its official version. This article is based on beta 6, which is close to the final version of Q. It would be better if i...

Android Q is about to launch its official version. This article is based on beta 6, which is close to the final version of Q. It would be better if it would be helpful to the people who read this article.

Private directories of Android Q
The private directory here is the App-specific directory. The specific path is probably under the "Internal Storage Device/Android/data/com.Project Package Name/", which is the private directory:
(1) After the APP uninstalls and inserts the code slice here, the data will be cleared.
(2) APP does not need any permission to access its App-specific directory.
(3) FileProvider can be used to share files using its own private directory.
Therefore, in sandbox Q system, the processing of files in this directory will not affect the structure of the internal storage directory, and it will automatically clean up after uninstallation with a very convenient "self-digestion" feature. Inside its directory, the file operation is just like the previous version of Q, and can be handled at will. This is not an overview here.
Public directory of Android Q
Public directories include: Downloads, Documents, Pictures, DCIM, Movies, Music, Ringtones, etc.
(1) Files in the public directory will not be deleted after the APP is uninstalled.
(2) APP can access the files through the SAF framework (System Access Framework) and the MediaStore interface.
(3) Public directory files cannot be accessed directly by path.
Interactive examples:

//Copy Sandbox Private Files to Download Public Directory public static void copyPrivateToDownload(Context context,String orgFilePath,String displayName){ ContentValues values = new ContentValues(); //values.put(MediaStore.Images.Media.DESCRIPTION, "This is a file"); values.put(MediaStore.Files.FileColumns.DISPLAY_NAME, displayName); values.put(MediaStore.Files.FileColumns.MIME_TYPE, "text/plain"); values.put(MediaStore.Files.FileColumns.TITLE, displayName); values.put(MediaStore.Images.Media.RELATIVE_PATH, "Download/Wintone"); Uri external = MediaStore.Downloads.EXTERNAL_CONTENT_URI; ContentResolver resolver = context.getContentResolver(); Uri insertUri = resolver.insert(external, values); //Log.i("Test--","insertUri: " + insertUri); InputStream ist=null; OutputStream ost = null; try { ist=new FileInputStream(new File(orgFilePath)); if (insertUri != null) { ost = resolver.openOutputStream(insertUri); } if (ost != null) { byte[] buffer = new byte[4096]; int byteCount = 0; while ((byteCount = ist.read(buffer)) != -1) { // Loop reads buffer bytes from the input stream ost.write(buffer, 0, byteCount); // Write the read input stream to the output stream } // write what you want } } catch (IOException e) { //Log.i("copyPrivateToDownload--","fail: " + e.getCause()); } finally { try { if (ist != null) { ist.close(); } if (ost != null) { ost.close(); } } catch (IOException e) { //Log.i("copyPrivateToDownload--","fail in close: " + e.getCause()); } } }


** The article is being updated... * *

3 October 2019, 17:22 | Views: 10078

Add new comment

For adding a comment, please log in
or create account

0 comments