Operational problems encountered when reading and writing files in Andrews Q (10), is recorded.

After acquiring the target file, call the method createNewFile try to generate a file in the specified directory and writes the contents to a file, the same way before and earlier in android9 no problem, after the Internet to find the basic point to the rights issue .

After introducing this look online to find many problems, android Q for the file read and write the introduction of new features in this version, READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE are limited, no longer like the previous version directly to a file. If you want to restore the authority of logic before, you can be set in the manifest file:

android: requestLegacyExternalStorage = "true"
can be solved (but not sure this method is not a temporary method, it is possible later Google will get rid of this way perhaps).

In addition, also be operated by a StorageManager getPrimaryStorageVolume (). CreateOpenDocumentTreeIntent () method, which is no way to manipulate files File class, you may be used similar DocumentFile

1 <application
2         android:sharedUserId="android.uid.system"
3         android:allowBackup="true"
4         android:icon="@mipmap/ic_launcher"
5         android:label="@string/app_name"
6         android:roundIcon="@mipmap/ic_launcher_round"
7         android:supportsRtl="true"
8         android:requestLegacyExternalStorage="true"
9         android:theme="@style/AppTheme">

Then recompile the apk, install open apk, normal in the corresponding file created under the specified directory

Guess you like

Origin www.cnblogs.com/aziji/p/12515514.html