I've got an application which writes large files to an external USB drive. The directory to write these files to comes from context.getExternalMediaDirs(), so it normally ends up being something like /storage/<UUID>/Android/media/com.app.package/.
My problem is that on all devices I've tested so far, this works. However, on a Sony Bravia TV (running Android 8.0) I am able to create files in the external media directory, but if I call mkdirs() to create a directory it always returns false.
My application targets API 28, declares the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions, and requests them both from the user at runtime.
It also seems that this problem goes away if I allow the Sony TV to "format the device as external storage", however this formats it to FAT32 which imposes file size limits that are unacceptable for my application.
Formatting the drive to NTFS via a PC allows files to be created, but not directories.
I suspect this is indicative of a bug in Sony's implementation, but I'd like some feedback from the community.
Has anyone encountered this on other devices? Is there a potential work around?
It doesn't make sense to me that I'd be allowed to create a file, but not a directory.
Related
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.
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.
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.
I am developing an application that has the following requirement:
When the device is connected to a computer via USB, the user should be
able to use Windows Explorer to drag files into and out of the
application directory.
The application will consume some of these files and produces others
which should be able to be copied back to the computer.
The target device does not have an external storage device (for
example an SD Card).
The directories that the files will be stored in should be accessible
whilst the application is running.
I've looked into the data storage page in the android documentation, but none of the methods stated there seem to do what I require.
Alternatively, is there a way to select the computer when the application is running and 'send' files via USB to the computer? How about for 'receiving' files?
What is the best way to fulfill this requirement?
When the device is connected to a computer via USB, the user should be able to use Windows Explorer to drag files into and out of the application directory.
If "the application directory" refers to a spot on external storage, this is possible.
The application will consume some of these files and produces others which should be able to be copied back to the computer.
If this is supposed to happen simultaneously, the device must be running Android 3.x or higher. Android 1.x and 2.x did not support simultaneous access to external storage.
The target device does not have an external storage device (for example an SD Card).
It needs to have something designated as "external storage". That does not have to be removable storage. On Android 3.x and 4.x, it is usually just a part of on-board flash that was designated to be accessible as external storage. In Android terms, "external storage" means "can be accessed by a host computer using USB and by all applications on the device as well".
The directories that the files will be stored in should be accessible whilst the application is running.
Again, this requires Android 3.x or higher. If this is a custom device, that most likely means you are going to need to use the recently-released Android 4.0 source code.
Alternatively, is there a way to select the computer when the application is running and 'send' files via USB to the computer? How about for 'receiving' files?
No and no, respectively.
What your going to want to do is use Environment.getExternalStorageDirectory. Even if there is no sd card, most android devices partition a part of the on board memory to be used as external storage.
I'm trying to find information on how to programmatically access the HTC Droid Incredible's supposed 8GB of Internal Storage Memory.
To determine the External Storage (SD Card) Location, I'm using the command:
android.os.Environment.getExternalStorageDirectory().
I've not been able to find any corollary for Internal phone Storage.
In examining HTC/Google Nexus One, Motorola Droid, and HTC Dream/G1 phones, there (as would be expected) does not appear to be any Mount Point for such Arbitrary Internal Storage.
On these phones the Internal Storage is divided amongst /data, /system, and /cache partitions.
The Incredible's Internal Storage is certainly not going to be located in /system. /cache is also unlikely given that it is globally non-readable/non-executable.
I'd read in reviews that the phone will still be limited to 512MB or so for apps, suggesting that it is not simply a subdirectory of /data.
I do not have access to a Droid Incredible unit myself, of course.
There is more information here: Droid Incredible storage mount points. It seems that Droid Incredible mounts its internal storage to /emmc, supposedly mounted r/w. It is not yet verified whether the WRITE_EXTERNAL_STORAGE permission is necessary in order to gain r/w access - I'm trying to get this information from Google Code
I will probably solve this by allowing the user two options to store the data:
SD-Card
Droid Incredible-only Internal storage
Edit: It seems that the WRITE_EXTERNAL_STORAGE permission is sufficient: according to droidForums both /sdcard and /emmc has the same GID of 1015.
Edit2: According to Google Group Thread the Incredible returns /sdcard as the result value of Environment.getExternalStorageDirectory(). Therefore, the user needs to decide whether he wants to use /sdcard or /emmc. The auto-detection of Incredible may be based on existence of the /emmc path.
As you're aware access to internal storage is usually limited to certain directories for each application by permissions. This is to stop one application reading data from another and from accessing system files without using the APIs. This makes sense since, for example, if you had an internet banking application you wouldn't want other apps to be able to access any of its cached data.
Each application gets to store data in a directory under /data/data. However, normally you don't specify the paths explicitly but used methods like Context.openFileOutput() which creates the file in the appropriate subdirectory of your application's directly.
I agree with you that it is unlikely that the majority of the 8GB of the Incredible's storage will be used for the /data partition.
So if they are going to have a separate partition to allow music and photos to be stored easily on the phone's internal storage then they will have to do it in a way that's compatible with existing applications. This means using Environment.getExternalStorageDirectory() but since the Incredible also supports SD cards then you're right in that it's not obvious how this might work.
There is a thread on the Android Developers Google Group discussing this exact question. Whilst there isn't an answer (at the time of writing) for how the Incredible works there's a post which says the Samsung Galaxy solves the same problem in this way:
The internal storage is mounted at /sdcard
If an SD card is also available this can be found at /sdcard/sd
This seems a sensible solution since it will be compatible with existing applications, including those which have mistakenly hard coded /sdcard instead of using Environment.getExternalStorageDirectory().
So my advice would be to use Environment.getExternalStorageDirectory() when you're looking for large areas for storage - either SD card or internal to the phone - and hope that each phone returns something sensible.
Just simply use this:
String primary_sd = System.getenv("EXTERNAL_STORAGE");
if(primary_sd != null)
Log.i("EXTERNAL_STORAGE", primary_sd);
String secondary_sd = System.getenv("SECONDARY_STORAGE");
if(secondary_sd != null)
Log.i("SECONDARY_STORAGE", secondary_sd)