Having trouble to get the files from android emulator (Titanium)

 ̄綄美尐妖づ 提交于 2019-11-29 13:08:54

Internal Storage is private to the app that stored them: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

Please use external storage for files that you need to access from apps other then those who created them.

Well, thanks @Fokke Zandbergen so much that remind me I had made a mistake that try to get the emulator's internal files through the external storage directory. And now, it's clear that if you want to get the local files from the emulator or real mobile device, maybe the follow suggestions may help you:

① Get local files from emulator

1 Android, try this path: file:///storage/emulated/0

First, the directory emulated is only special for the emulator, all the android emulator have this directory. And then, the directory 0 is means your emulator only have one internal storage directory, cause there're no external storage sdcard for the emulator.

[2] iPhone, try this path: /Users/xxx/Library/Developer/CoreSimulator/Devices/F34851D0-AFA5-443E-AEF6-70B695FB9C5E/data

For the directory F34851D0-AFA5-443E-AEF6-70B695FB9C5E, it's the simulator ID which you can check it by ti info command.

② Get local files from real mobile device

1 Android, try this path: file:///storage/sdcard0

Note this, sdcard0 is the internal storage of your mobile device. If you need to get the local files from external storage directory, also means SD card then you should try this way:

if(Ti.Filesystem.isExternalStoragePresent()){
    var sdkDir = Ti.Filesystem.getExternalStorageDirectory();
}

[2] iPhone, cause iPhone have not the external storage, so its same to the simulator. Well, I have not test this way, maybe you should have a try.



Well guys, I had tested the real mobile device file path recently, which I mean the file path of SDCard(external storage). However,there's a bad news I should tell you, the method that Titanium API afford to detect the if the external storage exists is not good to use. Here is the details:

  1. if(Ti.Filesystem.isExternalStoragePresent()) always return true although, the SDCard don't present.

    I supposed that, nowadays, almost all of the smartphones were built embed with a internal storage (never means the smartphone's selves storage like phonebook, I mean the internal storage is a special external storage but embed into the smartphone), the SDCard is a extend storage, but they're same.

  2. different manufacturer has different settings of the external storage

    During my test, when the smartphone comes from HUAWEI the external storage path become: file:///storage/sdcard1, distinguished with internal storage sdcard0.

    However, when the manufacturer is SAMSUNG, the external storage path is: file:///storage/extSdCard.

    So, we have to check the manufacture to define the external storage path:

    var sdCardPath;
    if(Ti.Platform.manufacturer == 'HUAWEI'){
        sdCardPath = Ti.Filesystem.getFile('file:///storage/sdcard1');
    }
    else if(Ti.Platform.manufacturer == 'samsung'){
        sdCardPath = Ti.Filesystem.getFile('file:///storage/extSdCard');
    }
    

    Well, it's so terrible!

So, I have been not get a good idea to approach the file from the real mobile devices by different manufacture. Guys, do you have a good idea?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!