Cannot write file to sd card on android kitkat - android

My tablet samsung galaxy tab 3 10.1 Kitkat cannot write (create folder/copy data) to sd card.
I was root the tablet, and use app like, nextapp sd fix, kitkat sd card full access in xposed installer and finally change permission acces manually, but still not working. any idea to fix that?

According to google, from Kitkat onwards it is not giving the permission to the application to write on the SDcard except from its package folder. That means, if you want to write something on SDcard with kitkat version, then create a folder structure like below on SDcard:
/Android/data/your.package.name/files/yourFiles
After which you can read as well as write inside this folder.But for the sake of caution please keep in mind that android will delete these folder after you uninstall or clear the data of your application

Related

how to save files on externalStorage

I've already figured out that on some devices the externalStorage may be set as the device Storage, like on my Samsung Galaxy 4 10.1 with 5.0.2. Android OS.
The Question now is how can I still say to save it on the SD-Card ?
For Example:
private File makeFolder(String folder) {
File dir = new File(Environment.getExternalStorageDirectory() + "/" + folder + "/");
if (!(dir.exists() && dir.isDirectory())) {
dir.mkdirs();
}
return dir;
}
On my older Devices (like my Sony Ericson Pro) this works just fine. So how to solve this?
You are into a slightly complicated area of Android programming :)
I can not give you complete answer here, but I can give some pointers:
On almost all devices I've seen, Environment.getExternalStorageDirectory() will give you the path to the root directory of an emulated SDCARD - which is not a physical SDCARD. Manufacturers are free to map the physical SDCARD to this path - but usually, they emulate an SDCARD using internal memory)
And prior to Kitkat, there are no API available to even to determine the presence of a physical SDCARD.
From Kitkat onwards, you can see if a physical SDCARD is present by checking the result of appContext.getExternalFilesDirs() which will give you your app's private data directory path on all available storage media.
If a physical SDCARD is present and mounted, appContext.getExternalFilesDirs() will give you two paths are result. Then the first one is for the emulated SDCARD. You may notice that this path will contain same subpath that returned by Environment.getExternalStorageDirectory().
The following example will make this clearer. I am assuming a Samsung S4 with a real SDCARD inserted and mounted in it
The first path returned will be:
/storage/emulated/0/Android/data/com.example.yourapp/files.
The second path is interesting - as this path is your app's accessible area on the the real physical SDCARD. This path will be of the form:
/storage/extSdCard/Android/data/com.example.yourapp/files
This is the only path that you have write access in Kitkat.
So, from Kitkat onwards, from the presence of these two paths, (and added checks for mounted SDCARD), you can easily find out whether your app is running on a phone with real SDCARD or not. You can even parse the second path to get the root directory of the real SDCARD (just remove /Android/... substring from this path)
And yes, now you know why you are so restricted with real SDCARDs in Kitkat. As said in italics above, you have write access to only that directory on a physical SDCARd in Kitkat.
Now comes Marshmallow and things changes again. In Marshmallow you have a storage framework, using which you can present the user with a permission dialog box and you can tell him to grant your app complete access to whatever device or directory therein. Please search for "Intent.ACTION_OPEN_DOCUMENT_TREE" for nice tutorials.
So, in short, as of now, there is no nice way in Android to deal with SDCARD which works uniformly in all versions. Before Kitkat, it is a grey area, In Kitkat, you are severely restricted, and in Lollipop, you are stuck with a system Activity with an absurd looking GUI for permission and not so easy to use framework.

can't read file from android internal storage

Im using a Camera intent to create a picture file in internal storage on android. This picture is saved in the app directory as
/data/data/com.company.app/files/test.png
This works fine, the picture is there.
When I with CCFileUtils then tries to check if the file exists (using js interface):
cc.FileUtils.getInstance().isFileExist("/data/data/com.company.app/files/test.png")
it returns false. Opening the file with CCSprite is totally hopeless too.
The owner and group of the app is the same as the app itself(i.e. "com.company.app"). The read/write permissions of my file is rw-rw-r.
EDIT: Adding information to add information.
The device from which I've extracted the information is a rooted Samsung Galaxy S running Cyanogenmod 11(exact build number: 11-2014112-SNAPSHOT-M12-galaxysmtd) which is built on top of android version 4.4.4.
Its internal storage so its the device own storage. That means it can't be on a sdcard if Im correct, im not sure, but its not removable media anyhow and its not in a sdcard folder on the device.
I've also tried to do the same on a 1+ one running CM11(exact build number: 11.0-XNPH44S). This device is not rooted so I can't check it's filesystem. But it seems to handle it the same way.

External Storage Write Access for Kitkat devices

The Problem
My app supports 4.0+ and it is all about file handling. It works perfectly in all Android versions except Kitkat.
In Kitkat, my app is unable to modify or write any files in SD card. But I see various apps like,
1) Solid Explorer
2) ES File Explorer
3) CamScanner
4) UC Browser
All of these apps give write access to SD card even in Kitkat devices without even root access.
Requirements
I need to have a fully functional way to create or modify files stored in the SD card in Kitkat. I seems to have troubles a lot of users and a proper solution will help many developers like me.
Yeah I came across that problem as well. After a lot of reading across the web the solution is to write only in your app folder (Ex: /sdcard/Android/data/packagename).
About those apps, on my s4 mini, es explorer cannot delete from external sdcard, so I think is different from device to device.
If the devices is routed change the permissions to gain write access anywhere on the sdcard.

Android Internal Storage advice

I am developing an app for University.
I have bought a Nexus 7 google tablet for the task (I wanted a tablet anyway :P)
I need to convert data I record on the app onto a text file that can be moved onto a PC.. Now, from what I can tell android has high security on 'Internal Storage' which is the only type of storage the Nexus 7 has, and I cant seem to be able to write a text file to a folder or anything.. and I can't even find the app's data folder on the windows explorer so I presume its hidden..
It appears its possible with 'External Storage' such as an SD card but the Nexus 7 does not have an SD card slot..
what should I do? Is it possible to be done on the Nexus 7?
All Android devices have "external storage" regardless whether or not they have SD card support (http://developer.android.com/guide/topics/data/data-storage.html#filesExternal). The naming is unfortunately misleading.
If you save your data to app's default external storage, you can access them on a PC in /Android/Data/[your app's package name]/files

SDCard content exist but cant see them

I am having very Strange problem with my Samsung Nexus with Android 4.0.2. I wrote a simple program which basically create file each time user presses a button. My program is working great on other devices where as on Galaxy Nexus Windows/Mac can not see those files on SD card, but when i do adb shell i see all files on SD Card.
I retest this on another Nexus which has Android 4.0.4 but still same result.
What could be the reason?
You probably need to index your files via MediaScannerConnection. Quoting myself from a blog post from last year:
...the MTP contents are not based on the literal contents of external storage. Instead, MTP contents are based on what files have been scanned by MediaScannerConnection. If you write a file to external storage, until and unless that file is scanned by MediaScannerConnection, it will not be visible to users over MTP.
External storage is scanned on a reboot and possibly on a periodic basis. Users can manually force a scan via utilities like SDRescan. However, the best answer is for you to use scanFile() on MediaScannerConnection to update the media database after you close your file. This will make your file immediately available to the user.

Categories

Resources