Search code examples
androidfilesystemssd-cardfile-copying

How can I transfer a file with special character to my Android SDcard?


Recently I'm in trouble about creating file in Android SD card with special character from iPhone.

My device : Galaxy Note4 KitKat. My PC : Window7

I got a file from iPhone to my PC. This file contains an emoticon (http://chars.suikawiki.org/string?s=%F0%9F%90%8D) I could transfer this file to internal SDcard from my PC but I could not transfer to removable SDcard.

Even I can't transfer copied file from internal to removable, too.( I used FileOutputStream, File.createNewFile to copy)

I suspected SDcard's file system and tried to other FAT16(2GB sandisk Sdcard ), exFAT(64GB samsung SDcard).

But I failed both.

I tried to found file system spec but i found nothing related. I also suspected reserved file title characters, but it was not related.

In short,

  1. Why cannot transfer this file to removable SDcard?

  2. How to copy programmatically this file to SDcard without renaming ?

===== add snippet =====

Below special character seems emoticon in Android device file browser but in my PC, it looks ordinal special character.

new File("/storage/emulated/0/🐍🐢🐙🐌.txt").createNewFile(); //internal storage. work.

new File("/storage/extSdCard/🐍🐢🐙🐌.txt").createNewFile();//removable storage. not work


Solution

  • I stumbled onto a similar issue with saving to SD. It appears to be a security issue. You now need to use the Storage Access Framework See Here.

    You could use the files allocated to your Application though and not have to use the Storage Access Framework. One way to access your Applications data directory is by either using:

    ContextCompat.getExternalFilesDirs(context, type)
    

    Which would be backwards compatible. Or you could use the following for Lollipop Users

    Context.getExternalMediaDirs()
    

    Each of this method will give you 2 Directories. 1 for internal memory and other for SD (If device has slot). From here you can save all your application specific data.

    BE WARNED: this data will be deleted if user ever uninstalls your application.

    Hope this helped!