Solution of mediaprovider unable to write data to files in external SD card under Android 4.4

This article describes the solution that the mediaprovider under Android 4.4 cannot write data to the file in the external SD card. Share with you for your reference, as follows:

The Android 4.4 platform restricts the application's read-write permission to the external SD card. Mediaprovider restricts the reading and writing of external SD card through checkAccess method.

From the above code, we can see that if sexternalpath does not point to the external SD card and path is the file path of the external SD card, the method will throw FileNotFoundException. Sexternalpath generally points to the internal storage

In applications, we usually use contentresolver.openoutputstream (URI) to open the file stream of media files on the memory card. If the media files are on an external SD card, we cannot open the corresponding file stream, and naturally we cannot write data to it.

In order to solve this problem, we can only change the restrictions of mediaprovider on writing data to SD card under Android 4.4 platform. The specific modification methods are as follows

We can read and write file paths that meet the issecondaryexternalpath (path). For files with an external SD card, the issecondaryexternalpath (path) must be true

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>