Useful Tips

Getting the path to an Android SD Card

Pin
Send
Share
Send
Send


| 18.04.2017

It's no secret that the operating system Android widespread in the mobile world.

Such widespread use of the brainchild from Google provokes an increase in the number of hacker attacks on this platform. In order to deal with this unpleasant moment, the IT giant is trying to introduce new features aimed at increasing the security of owners of devices with the Android system, but some of these functions may become a source of additional inconvenience. How to eliminate one of these inconveniences will be discussed below.

Restricting access to the memory card

Why Android programs do not have access to the root of the sd card?
The fact is that open access to the root of the drive is a big security hole in the entire operating system. Making attempts to protect users from malicious users, Google took such a step as restricting access to a memory card.

This situation does not suit everyone, so below we will consider a way to return third-party programs access to the root of the memory card.

NextApp SDFix

Immediately, we note that in order to solve the problem, we need root-rights for the user in the Android system. In the article We remove ads on Android. Hosts file we have already touched on this definition. Below is a short excerpt:

root - These are superuser rights on UNIX-like systems. To be more precise, then root - This is an account whose owner has privileged access rights and changes to the file system

So, in fact, we have two options:

  • software (in automatic mode),
  • manual (editing system files).

To use the software method, we need to download the application to our device SDFix: KitKat Writable MicroSD from company Nextapp from the Google Play store or from the file attached to this article: nextapp.sdfix

Install the program and run it, giving root permission

We agree to make changes and click on the Continue button
After some waiting, the program will display a message about the successful completion of the operation

In addition, before making changes to the program SDFix creates a backup copy of editable files, which is saved along the way

If necessary, we can always restore the original file, having previously deleted the ending .original-pre-sdfix in his name. The file is replaced by analogy with its change, this process is described below.

Manually providing access to a memory card on Android

Troubleshooting recording to an external SD card in Android 4.4+ is also possible in manual mode.
It should be understood that the aforementioned SDFix program only performs one function, which can be reproduced independently.

Moreover, if the program generates an error during operation, then doing the same operation manually may well be crowned with success.

Here is a step-by-step instruction on editing a file platform.xml

  1. We make a backup of the smartphone system. We need a backup to be able to roll back in case of unforeseen circumstances and failures. You can simply make a copy of the file that we are going to edit, but it will be more reliable to make a full backup of the system from recovery
  2. Now run any Android file manager, let's say it will be Total commander
  3. Go to the directory
  4. Copy the file from the directory platform.xml to any convenient place
  5. Open the created file with a text editor to make changes
  6. We find in the file a piece of code that looks like:
  7. And before the closing tag, write the following line:

As a result, we should get the following code fragment:

  • Save changes
  • Copy the edited file back to the folder / system / etc / permissions /, agreeing to a replacement (that is, when prompted, click Overwrite)
  • Now in the properties of the file we set it rights rw-r - r-- (the code corresponding to this setting is 0644)
  • We reboot the device.
  • That's all. After your device boots up, third-party applications will be able to write their data to the root of our flash card.

    We have provided access to the root of the memory card for Android programs.

    Full rights and limitless possibilities.

    Terminology

    Google tells us that there are the following concepts:

    1. Internal (internal) The memory is a part of the memory card built into the phone. When using it, by default, the application folder is protected from access by other applications (Using the Internal Storage).
    2. External (external) memory is a common “external storage”, i.e. it can be either part of the internal memory or a removable device. Usually this is part of the built-in memory, the last time I saw a removable device on android 2.2, where the built-in memory was about 2GB, and the connected memory became external (Using the External Storage).
    3. Deleteable (removable) memory - all storages that can be removed from the device without "surgical" interventions.

    Prior to KitKat 4.4, the API did not provide functionality for obtaining paths to external memory. Starting with this version (API 19), the function public abstract File [] 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? The path to it we again can not get.

    Method 1 (simple option)

    After Root is installed on your Android smartphone or tablet, go to the Google Play app store and download SDFix: KitKat Writable MicroSD (free). After installation, go to the SDFix application and click "Continue"

    Then wait a couple of seconds until the error is fixed. Close SDFix and restart Android for the changes to take effect! Everything!

    Method 2 (simple, an option for those who want to know more)

    The method described above is automated, but you can fix it by hand, especially since it is not at all difficult! To do this, you need to install the file manager application, for example ES Explorer, after giving root access to the system partition first.

    Go the file manager to the system partition:

    Then open it with the built-in text editor ES Explorer

    Add another parameter just below.

    Restart your Android smartphone or tablet for the changes to take effect! The problem with accessing the memory card has been resolved!

    The method in the presence of root access (any Root manager is suitable).

    So, first we need the SDFix program (it is available on Google Play), open the link and click install.

    We start, read the warning that it is possible to break the phone, but we are lucky therefore we press the button Continue.

    Put a check in the checkbox and click again. Continue

    After clicking the application, the program will require root access from the device, if you have SuperSU, then we give root, if not, we see this message:

    As I said, I will use the built-in root, so we are looking for the “Security»On the desktop and run the application. Click the button "Permissions«.

    And we tap on our SDFix, if you do not have it in the lists, then you did not go through the first steps of this instruction, to use the standard root a request from the application is required.

    We wait five seconds and confirm the permission to grant increased rights.

    Open SDFix again, and repeat the first steps of this instruction, the output will be the following window.

    It says that access to the USB flash drive was received by all the applications that requested it and you need to restart the phone. We restart and remember that after updating the firmware, the steps will have to be repeated.

    Method for phones without root

    If someone still does not understand, then almost this entire site is a quality rewrite, a text about the complex, rewritten in the simplest possible language personally by me. I don’t indicate the sources, as I’m just looking for inspiration in other people's articles, and not trying to copy them. So, here they sent a link to an article with this method in the comment, so why not rewrite it to help users without root who have already reached this site.

    I’m going to switch to MIUI 8 from miui.su, access to the USB flash drive is always by default, so I can’t check, but according to the idea, this method can also suit other versions of Android.

    Open “Settings” → scroll down the list and click on “All applications”.

    Scroll to the bottom and see there “Documents” marked “Disabled”. Tap on it.

    At the bottom of the screen, click on the "Enable" button.

    The most interesting thing is that it does not seem to turn it off manually manually, but oh well, we don’t need it. We go to the file manager who needed access and check its availability.

    Look like that's it. I hope this article was useful to you, click one of the buttons below to tell friends about it. Also subscribe to site updates by entering your e-mail in the field on the right or by subscribing to the group in Vkontakte.

    Thanks for attention

    searching results

    To answer this question, I turned to the all-knowing Google. But he did not give me a clear answer. Many options were considered for determining from the use of standard functions that lead to external memory, but they have nothing to do with deleted storage devices, to the processing of device mounting rules (Android works on the Linux kernel). In the latter cases, “wired” paths to the folder with mounted devices were used (in different versions this directory is different). Do not forget that from version to version the mounting rules change.

    In the end, I decided to combine all the knowledge gained and wrote my own class, which can return the paths to external and removable devices to us.

    Code Description

    Class was created Mountdevice, which contains the path to the device, the type of device and some hash.
    There are two types of devices allocated (I did not touch the internal memory, since access to it can be accessed through the system API).


    And a 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 implementation.

    Method One - Environment

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

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

    The solution is taken from stackoverflow. The answer is down there somewhere.

    Method two - mount

    Since for a long time I could not get the system to tell me the path to the deleted memory, I decided to look in the direction of the mounted devices. The system has configuration files that describe the rules for mounting external devices. Everything would be fine, but on Android version 4. * there are no mere mortals access to this file, so I will not consider this method.

    Back to the mount utility. When launched without parameters, the command returns a list of mounted file systems. Deleted devices usually have the format of the FAT file system, then we will highlight lines in which there is a characteristic "fat". External memory will be characterized by the parameter."fuse".

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

    The solution is taken from stackoverflow. The answers there are somewhat approximately the same.

    About duplication

    Many noticed the following picture in the device mount directory:

    And most interestingly, all this is the same external memory card. Such fragmentation begins with the Jelly Bean version and this is done to support the multi-user mode of the system. More details here. And so, in order not to get the same memory card as different devices, a way of determining identity is needed. If there was access to the mount configuration, then there were no questions. But there is no access. Therefore, here I spied a solution with a hash calculation for each device:

    1. create StringBuilder
    2. write to it the total size of the device and the size of the used space of the device
    3. bypass the contents of the root of the device
    4. write the name of the directory
    5. write the file name and size
    6. compute hash

    Pin
    Send
    Share
    Send
    Send