Android 5 sd card is read only. Getting the path to the SD Card on Android

💖 Do you like it? Share the link with your friends

Many happy owners of devices with 4.4.2 “on board” have probably already encountered the problem of the inability of most applications installed on the device to write data to a flash card. Made, according to Google, in order to make the Android 4.4.2 KitKat OS a more secure system.

Restrictions on writing to a flash card apply primarily to applications installed from third-party sources. And, most importantly, Android 4.4.2 KitKat prohibits modification of files that are not directly related to the applications that want to make this modification. Hence the inability to record to an SD card.

In practice, this limitation literally means the following: use standard instant messengers, photo editors, file managers! Because if the developer of your software was unable to respond in time and add an update to your photo editor, for example, then all your edited photos will be “live” while the photo editor is running - you will no longer be able to write your edited photos to the card!

More advanced users who constantly copy data from a flash drive to a computer and back may encounter the following problem: the computer detects your “ ”, sees the files, but cannot do anything with them - access is denied! This problem can be corrected by installing an application on your device that will give access to . But this application will only work on ROOT devices.


SDFix: KitKat Writable works simply: after installing and launching the application, you click on Continue, agree to the terms and click on Continue again. If the Superuser application is already installed on your device, then you should allow SDFix access to ROOT directories in it.


SDFix KitKat Writable MicroSD during its operation will change the file /system/etc/permissions/platform.xml, in which it will write permission for writing and modifying files by applications that have the WRITE_EXTERNAL_STORAGE permission. Original modified SDFix: KitKat Writable MicroSD file you can find it by name platform.xml.original-pre-sdfix. Subsequently, you can always restore the original file.

For the most “handy” users who have ROOT access on their device, there is an option to make corrections to required file, without resorting to SDFix: KitKat Writable MicroSD.

To do this, launch a file manager that can edit files, find the platform.xml file at /system/etc/permissions/, and open it using the built-in editor.


After that, find the android.permission.WRITE_MEDIA_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE sections and add the following lines of code in these sections:







After that, save the modified file in the editor.

After rebooting the device, all unpleasant problems associated with the inability to write and modify files on the flash card will be solved.

It's finished! The tablet, namely the Asus MeMO Pad 7, which I replaced my honest hard worker, received an update to Android 5.0.1. Now I have a device with Lollipop, or, as they say on the Internet, with Lollipop.


The update arrived somewhat unexpectedly. To be honest, I waited in April new firmware to phone ( Asus ZenFone 5) - at least it was promised. No one said anything about the tablet, and here it’s up to you, get it and sign for it.

This, in fact, discouraged me (in a good way, of course), also because I purchased the tablet in December, and it had version 4.3. That is, this is the second significant update operating system(in fact, there were more updates, but the Android version number did not change). The previous manufacturer of my devices - Samsung - could not boast of such a rate of fire, although they also updated the operating system twice: from Android 3.2 to Android 4.1.2 (via 4.0.1). But we had to wait much longer for these new versions.

Well, long live surprises! Receiving notice of exit new version firmware, I immediately downloaded it, which is more than 700 meters, and launched the update. Since I didn’t download through home network, and through a mobile phone, it took a little more time to do everything: from the start of the download to the completion of the update, about an hour passed. The update itself lasted about twenty minutes, but potentially could take longer - because after installing the operating system, the process of updating the installed programs follows. My counter counted up to 205. But now, the process is over and it’s time to see what has changed.

The first thing that caught my eye was the more sophisticated graphics when unlocking the device. The second is the hand in the notification area. I endured it for a couple of days, hoping that by chance I would see something related to it somewhere. I didn't see it. Then I began to search purposefully and found an explanation for it on 4pda. It turns out that notifications are divided into important and not so important, and it is possible to specify which notifications you want to receive. If you set the option Always notify , then the hand disappears if the option Only important alerts , then the hand appears. To be honest, I removed my hand several times, but for some reason it always comes back. Why? I don't know yet.

Here, in fact, is the procedure for “removing” this hand:

The method given above is not complicated at all. But you can achieve the result even faster and easier: press one of the two volume control buttons - a window will appear on the screen that allows you to change the volume levels for various system components, and also, attention, control Alert modes . True, for some reason, these same Alert Modes are not always displayed in such a fast manner. I haven’t found a pattern yet, but, to be honest, I didn’t really look for it.

A few words about installed programs. Although before starting the update process I received a warning that some programs would be deleted because they were not included in the new firmware, nevertheless, most of the programs remained.


The only thing I'm a little sorry for is the program with the atypical name "Two Applications". Although, I must admit, I didn’t even immediately understand what it was about: I thought which two applications would be deleted, was it really impossible to indicate the names.

Yes, the program that appeared in version 4.4.2 and made it possible to share the screen between two simultaneously running applications has sunk into oblivion. To be honest, its functionality was rather weak, since it was possible to run a very limited range of applications at the same time. If memory serves, I only used it once or twice, just to see what it was like. Maybe someone will miss the opportunities provided by this program, but somehow I wasn’t particularly upset. Although, of course, I don’t really like it when they take away from me what they previously gave me.

A couple more comments about the programs. After I moved to a new tablet, I spent some time installing on it the programs that I used on my previous device. Some of them happened, but we are not talking about them now. We are talking about those programs whose behavior has changed something. Of course, I haven’t tried everything yet, but here’s what I’ve discovered so far.

TuniIn Radio Pro, which I bought, by the way, absolutely did not work on KitKat. Everything went smoothly - until the turn came directly to listening to a radio station. That is, the program was launched, I selected a group of radio stations, for example, Local Radio Stations, selected a specific station (for example, RockFM, Radio Jazz, or any station in general), after which the program crashed with an error. Sometimes there was even sound, but the program still crashed. Time passed, TuneIn Radio updates were released, but nothing changed. However, after updating to A, the problems magically disappeared, and now everything works without the slightest complaints.

Another positive change - office suite SoftMaker Office HD, also honestly purchased. The programs included in it worked normally on the Samsung tablet. When I installed these programs on a new tablet, they did not start at all. After some time, an update for this office was released and the situation improved somewhat: programs began to launch, however, during operation, some strange graphic artifacts accumulated in the menu area (top line of the program window). When switching to the desktop (or another application) and back, the artifacts disappeared, but not for long. After Android updates All programs included in the package work like clockwork.

Well, a small negative point. I use, very actively, a program called DVR. I also paid money for it too. The program worked fine on the new tablet, no complaints, plus, functions that were not available on the previous tablet worked, for example, video stabilization. After updating the OS, the program began to crash steadily when starting recording. At first, I thought that there were some problems with recording to the memory card - I was configured to write to the program directory on an external MicroSD card. But, after I was able to create a subdirectory in the recording directory in the program itself, it became clear that using an external card had nothing to do with it. Then I decided to disable one program function at a time, and the first thing my finger touched was the checkbox with the stabilization checkbox. After turning off the option, the program began to record video, but its quality dropped. No, the resolution and flow rate - everything remained the same, but the picture on the recording floated in waves. There is a setting in the program that tries to smooth out this effect, and, in principle, turning it on helps somewhat, but for some reason, when you re-enter the program, the mark that the option is enabled remains, but the picture floats, as if the option is disabled . If you click on an already enabled option, everything will immediately return to normal. Most likely, this is a bug in the program, I'm going to report it to the developer and, perhaps, the author will fix this glitch. But the fact that video stabilization does not work is a little annoying. First of all, because the standard camera program has a stabilization option in the settings and, when it is turned on, recording is carried out without errors.

From special cases related to programs, I will move on to more general properties of the system. Well, firstly, the amount of free memory has increased. As I already wrote, all my software remained in place. At the same time, I must say that I strain the tablet quite a lot. Not in terms of the fact that I constantly play games, but in terms of the fact that I have a lot of services hanging on, some of which I may not use, but I keep just in case. We are talking, first of all, about all kinds of mailers - Outlook, Yandex Mail, GMail, more precisely, now Inbox. Next, various cloud storage- Yandex Disk, OneDrive, Google Drive, Dropbox, Box, Asus WebStorage. Couple social networks- Odnoklassniki and Google+. All sorts of other messengers - Viber, ICQ, Skype, Hangouts. All these programs, one way or another, eat up the device’s memory, even when you don’t use them. But, in principle, I understand what I’m getting into.

Users of Asus devices know that there is an application in the Android curtain that allows you to clear memory, at least temporarily. In the top five it is called Cleaning, but in KitKat it was called more fancifully - Strengthening. When you open the curtain, the icon of this application shows the amount of free space. this moment memory. So, when Android version 4.4.2 was installed on the tablet, this figure fluctuated in the range of 200-300 MB and the icon, most often, was yellow. Now the amount of free memory varies from 400 to 600 MB and the icon is green almost all the time. This change is probably due to the change virtual machine, used in Lollipop, but perhaps something has changed in the firmware itself, for example, Asus has removed something. In general, we need to figure it out.

Changing the virtual machine should have affected two more parameters - performance and power consumption. What can I say about performance? Nothing, probably. I don’t play with toys, I don’t really like competing with parrots (Antutu, etc.). The tablet itself is quite powerful, so I didn’t notice any slowdowns either on KitKat or now in Lollipop. Everything is smooth and without complaints. When I'm driving, the DVR, Strelka, Maps (either Yandex or Google) work, I also listen to music using Kodi, and, after all this, it still responds to switching to the desktop, launching some other programs, in general, are a beast.

And about energy consumption... Basically, the latest update on KitKat deprived me of the opportunity to complain about the inefficiency of the device. If after the initial installation of KitKat the tablet lost 20-30 percent of its energy reserves per night, then after updating to the 31st firmware version, the losses became quite acceptable - from two to five percent per night. Updating to Lollipop did not worsen anything in this sense, and thank you very much for that. As for consumption under load, here again I can cite operating experience in a car: all the same initial ones - DVR, Strelka, Yandex Navigator, Kodi, screen brightness is about 75-80 percent - a bright, sunny day, plus all wireless interfaces are turned on , so, during the trip - about two hours - the battery was discharged to 57 percent. In my opinion, quite worthy. By the way, under KitKat it was about the same.

Well, the last thing - listed in order, but not in order of importance - is what I would like to note. We will talk about working with an external memory card. I, as I was getting out of the situation caused by KitKat's restrictions on recording to an external memory card. Apparently, the wave of negativity was so strong that Google had to listen and change something. Or maybe they just changed something without listening to anyone. But let’s leave this important question aside (did we listen/didn’t listen), and let’s move on to the changes themselves.

Google allowed third party programs write to the memory card. In principle, he did not prohibit it before, it was just that the permits were issued in such a way that, if normal conditions, only the native file manager had write access to the entire external card. Well, maybe some manufacturers allowed access to their other programs, but I only encountered the file manager. Now any program can write, but for this several conditions must be met.

First, the program must use the new features of the Storage Access Framework, namely, use the OPEN_DOCUMENT_TREE intent and several new, or updated, SDK functions.

Secondly, the user must decide for himself which branch (or branches) to go to. file system it will give access to one or another application. That is, you can give access to the entire card if, in response to a request for access, you specify its root, or you can give access only to a specific folder and its child elements. In general, you will have to take responsibility on yourself, and, if something happens, you will also only have yourself to blame.

Third is luck. On my tablet everything worked as it should, on my friend’s HTC One M8 - did not work, although online is there a video, how everything works great on this smartphone model. There is an assumption, however, that it didn’t work because the card in his phone was formatted somehow wrong, maybe without indicating the volume name, or maybe in the wrong file system.

In fact, this is both joyful and sad news at the same time. Joyful - because now you don’t have to receive root access to the device and you can not be limited only to the application directory. Sad - because until the developers deign to use the new API and release new versions of their programs, nothing will work. From my experience: file manager ES Explorer has already acquired support for the new API, and I was able to give it write rights to the entire external SD card, but the Total Commander file manager did not and still cannot write to the MicroSD card - anywhere except its own directory. Like this.

In fact, there are quite a lot of nuances in this whole story with recording to an external memory card. For example, you gave some programs access, but forgot others. Where to look? As I understand it, currently - nowhere. That is, in principle, you can watch it, but not on the tablet itself, but on the computer, if you connect the tablet to it and use adb program. Here's the command you need:

Adb shell dumpsys activity providers

But I haven’t found how to get the same thing on a tablet.

Next question. You gave some application access to write to some folder, and then you changed your mind and want to take it away. Is there such a possibility? Fortunately yes. But with losses. The first, very radical way is to remove the program and reinstall it. The second method is not so radical, but also not ideal - you need to clear application data in the device Settings. Naturally, along with access rights, other program data will be deleted, so a logical question arises about practical applicability this method. It was not possible to discover other methods, perhaps yet. You can use both methods if you first back up the program data, and after putting one of the methods into effect, restore it. But here the question arises about the capabilities of backups - will only data be backed up, or data along with permissions? If with permissions, then after recovery, well, you understand... All this greatly depends on the specific applications used, so you should be very careful. And this is another good reason to think before you see ancient Moscow, without the sanction of the relevant authorities, grant rights to any application to access the file system of an external card.

Further more. What happens if you change the card inserted into the slot of your tablet? The answer is that you will have to separately grant access to each card you insert into the device. In principle, this is probably logical. That is, you gave the file manager access to the root of the card, then took it out and inserted another one. The file manager will not write to the new card; you will have to give access again. But when you return the first card to the tablet, the file manager will write to it without problems.

One more question. So you gave the application access to some folder, not the root one. Time passed and you needed to allow write access to the same program in another folder on the same card. Can this be done? In principle, this is a consequence of the previous case, so the answer is: yes, it is possible. That is, the system for each application will remember the list of directories to which you have given write access.

Now there is a nuance associated with the applications installed on the tablet for each user whose profile was created on the device. Here, too, everything is logical - for each user of the device, their own access rights for applications are stored, that is, everyone is the architect of their own happiness, or, if you like, their own evil Pinocchio.

And of course, a lot depends on the qualifications of the developers. It may happen that you give rights to some program to access the external card for writing, and after rebooting the tablet you find that there is no access. In such a situation, only the program developer is to blame - he did not take care to maintain the permission received. Perhaps you should think about it and look for an alternative to this program, because you never know what such a programmer did not provide for.

Oh, yes, this is what the process of issuing recording rights to a microSD card for ES Provodnka looks like:

We need an external card

Let's try to create something right at the root of the map






We need to display the SD card


Here it is, our external memory card



Well, that's it for now.

P.S. It so happened that quite a lot of time has passed since I wrote this material. I could have published it many times already, but I kept putting it off, and it’s unclear why. More precisely, I know why - I was still deciding how best to present a series of screenshots describing a particular process: as just a sequence of inserted images, or as a slide show. Ultimately, the decision was made to use (at least for now) a sequence of images. How all this happened is a topic for a separate post. For now, everything remains as it is, the only pity is that a lot of time was wasted. The only consolation is that it was not in vain. In addition, a pleasant event occurred. I wrote in this post that access to an external memory card will only be available when program authors start using the new API. As an example of a program in which the new API is not used, I gave Total Commander. So, while I was delaying publication, Total Commander was updated, and now it can also work with an external memory card in Android Lollipop style. Below I provide a series of screenshots describing the process of creating a new directory in the root of an external memory card using Total Commander:

Selecting an external memory card
and select the desired item from the menu
That's probably all for now.

I bought new phone Samsung Galaxy S5, and immediately encountered a problem in the operating room Android system. More precisely, version Android 4.4 KitKat. This version of Android introduced new feature Google developers.

Applications are now denied access to editing files on the SD card!This causes some applications to not work!

I'll tell you how to get around this problem!

Good afternoon, dear readers of our blog!

The other day I bought myself a new phone! Samsung Galaxy S5!

ENJOYING YOUR NEW PHONE

I congratulate myself on a successful purchase, which I have been dreaming about for several years! The phone turned out to be remarkably fast, powerful, beautiful and convenient!

Previously, I already had an HTC phone (it’s about 4-5 years old) with an Android system. One of the first phones with such a system (at the time of purchase). I studied it inside and out, reflashed the system several times, and chose the Android firmware, which was much superior in functionality to the official one at that time.

For those who don't know, flashing is a replacement of the phone's operating system. Well, that's about it reinstalling Windows on the computer.

A lot of time has passed, many versions of Android have been released (at the time of purchase I had Android 2.2). The new versions and the phones on which they were installed are much superior to my old smartphone. Therefore, I was very surprised by the power, speed and functionality.

I enjoyed it for about 4 days. Then I came across a problem!

PROBLEM! The file system prohibits editing the file!

After the next update, the phone's operating system itself was updated to Android 4.4.

Imagine my surprise when I couldn’t edit a single file on my own phone! At first I was guilty of glitches, I checked in different folders, tried to edit the file from the computer (by connecting the cable to the phone). There was no way to edit the files!

After looking at the information about the operating system in Settings - About device - SE Status for Android, I saw the word Enforcing.

This is code word Google means a version of Android where application rights are limited at the operating system kernel level! EMAE! Well, I got it!

I turned to the Internet to solve the problem

Here's what I found:

X I just noticed that my phone is completely new, with a 5-year manufacturer’s warranty!

If you get Root access (administrator rights in the Android system), then the warranty from the manufacturer (Samsung) disappears. In fact, some hacker sites claim that there are special methods to return the factory counter to its original position. The factory counter is reset to zero when Root access is obtained. This indicates to the service company that the phone has been hacked and is not covered under warranty.

To influence this counter, you need to disassemble the phone and get into the chips. Therefore, do not fall for such deceptions!

If you get Root access, your warranty will disappear! Tested on my old phone!



In the new version of Android 5.0, Google uses a different logic for blocking access to external SD memory cards.

1. How does the new logic work?

Applications are installed on the system in compiled form. That is, in a form ready for launch. This increases performance, multitasking and reduces battery consumption.

In other words, previously there were distribution files in the system ( setup files) and the system, when starting the application, compiled it before launching. In other words, the files were packed, while the application was running, the files were unpacked and launched.

Now, in Android 5.0, all applications are installed in a compiled, unzipped form. This results in applications using more space but running faster!

2. What does this lead to?

  1. Access rights are assigned to the application DURING INSTALLATION!
  2. The user has the right to set the rights for a specific application during installation.
  3. The user can change the permissions of the application. For example, if you trust a program, you can allow it to edit files on an external memory card.

I WANT TO UPDATE ANDROID TO VERSION 5.0 to solve the problem!

If I update the OFFICIAL version of the operating system, I WILL KEEP THE WARRANTY!

But I need a version of Android for Russia (specifically for her, and not for another country), so as not to suffer with in English words in the interface.

I'll try to find her.

Official support program Samsung phones Kies says my phone is updated to latest version By.

I did not find any official Android updates (for our region) on the official websites.

I found information on the forums that Google released a firmware version for Russia in January 2015. But it is being implemented very slowly on customer devices.

This way, I can wait until my device receives a message that there is a software update. After that I can update Android.

While developing a competition application, I encountered a database storage problem. The problem was how do I identify the external memory card. In general, a search on the Internet did not give an exact answer. Therefore, combining all the results found, I assembled my class. If anyone is interested, look under the cut.

So, let's start with the theory.

Terminology

Google tells us that there are the following concepts:
  1. Internal ( internal) memory is part of the memory card built into the phone. When used by default, the application folder is protected from access by other applications (Using the Internal Storage).
  2. External ( external) memory is the general "external storage", i.e. this can be either part of the built-in memory or a device that can be removed. Usually this is part of the built-in memory, the last time I saw a device being removed was on Android 2.2, where the built-in memory was about 2GB, and the connected memory became external (Using the External Storage).
  3. Deleted ( removable) memory - all storage that can be removed from the device without “surgical” interventions.

Prior to KitKat 4.4, the API did not provide functionality for retrieving external memory paths. Starting with this version (API 19), the public abstract File function appeared getExternalFilesDirs(String type), which returns an array of strings with paths to internal and external memory. But what about our SD Card, which is inserted into the slot? We again cannot get the path to it.

searching results

To answer the question, I turned to the all-knowing Google. But he didn’t give me a clear answer either. Many definition options were considered, from using standard functions that lead to external memory, but they have nothing to do with the storage devices being removed, to processing device mounting rules (Android runs on the Linux kernel). In the latter cases, “hardwired” paths to the folder with mounted devices were used (in different versions this directory is different). Do not forget that mounting rules change from version to version.

Ultimately, I decided to combine all the knowledge I had gained and wrote my own class, which can return paths to external and deleted devices.

Code Description

A class has been created MountDevice, which contains the path to the device, the device type and a hash.
There are two types of devices ( internal memory I did not touch it, since it can be accessed through the system API).

Public enum MountDeviceType ( EXTERNAL_SD_CARD, REMOVABLE_SD_CARD )
And the class was created StorageHelper, which searches for available memory cards.

The StorageHelper class implements two search methods - through the system environment ( Environment) and using the Linux utility mount, or rather the result of its execution.

Method one - Environment
When working with the environment, I use the standard getExternalStorageDirectory() function to obtain information about external memory. To get information about the memory being deleted I use environment variable "SECONDARY_STORAGE".

External memory there is always one and usually there is always one, so we check it for readability, calculate the hash and remember it. There can be a lot of memory to be deleted, so it is necessary to split the resulting string by delimiter and check each value.

function fillDevicesEnvirement

String path = android.os.Environment.getExternalStorageDirectory() .getAbsolutePath(); if (!path.trim().isEmpty() && android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) ( testAndAdd(path, MountDeviceType.EXTERNAL_SD_CARD); ) // Get the remover String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE"); if (rawSecondaryStoragesStr != null && !rawSecondaryStoragesStr.isEmpty()) ( // All Secondary SD-CARDs split into array final String rawSecondaryStorages = rawSecondaryStoragesStr .split(File.pathSeparator); for (String rawSecondaryStorage: rawSecondaryStorages) ( testAndAdd(rawSecondaryStorage, MountDeviceType.REMOVABLE_SD_CARD); ) )


The solution was taken from stackoverflow. The answer is somewhere down there.
Method two - mount
Since I couldn’t get the system to tell me the path to the memory being deleted for a long time, I decided to look in the direction of mounted devices. The system has configuration files that describe the rules for mounting external devices. Everything would be fine, but on Android version 4.* mere mortals do not have access to this file, so I will not consider this method.

Let's return to the mount utility. When run without parameters, the command returns a list of mounted file systems. The devices being deleted are usually in the FAT file system format, so we will highlight lines that contain the characteristic " fat". External memory will be characterized by the parameter " fuse".

Note: when using this method, the types of mounted devices are not always determined correctly (most likely I did not take something into account). Noticed the difference on different Android versions. Therefore, this method can be used as an additional one.

fillDevicesProcess function

try ( Runtime runtime= Runtime.getRuntime(); proc = runtime.exec("mount"); try ( is = proc.getInputStream(); isr = new InputStreamReader(is); br = new BufferedReader(isr); while ((line = br.readLine()) != null) ( if (line.contains("secure ")) continue; if (line.contains("asec")) continue; if (line.contains("fat")) (// TF card String columns = line.split(" "); if (columns != null && columns.length > 1) ( testAndAdd(columns, MountDeviceType.REMOVABLE_SD_CARD); ) ) else if (line.contains("fuse")) (// internal(External) // storage String columns = line.split(" "); if (columns != null && columns.length > 1) ( // mount = mount.concat(columns + "\n"); testAndAdd(columns, MountDeviceType.EXTERNAL_SD_CARD); ) ) ) ) finally ( .. . ) ) catch (Exception e) ( ... )

Source The whole class is located nowhere yet. One of these days I'll try to post it on gitHub.

Who else uses what methods?

Tags: Add tags



tell friends