Issue
guys! I have trouble to get files from my android emulator!
① Here is my emulator info: Genymotion for personal use - Samsung Galaxy Note 3 - 4.4.4 - API 19 - 1080x1920
② And here is the file's tree of the emulator:
I had stored two mp3 files for test in the Internal storage directory, and the path is /storage/emulated/0/Download.
As you can see, the two mp3 files are in the Download directory. My trouble is that I can never get the two files right path.
③ Here is my code:
if(Ti.Filesystem.isExternalStoragePresent()){
var sdkDir_1 = Ti.Filesystem.getExternalStorageDirectory();
console.info('------------->sdkDir_1');
console.info(sdkDir_1);
var sdkDir_2 = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory);
console.info('------------->sdkDir_2');
console.info(sdkDir_2);
var downLoadDir = Ti.Filesystem.getFile(sdkDir_2.parent.directoryListing[7]);
console.info('------------->downLoadDir.getDirectoryListing()');
console.info(downLoadDir.getDirectoryListing());
...
and here is the console:
[INFO] [android, 4.4.4, 10.0.3.15] ------------->sdkDir_1
[INFO] [android, 4.4.4, 10.0.3.15] appdata://
[INFO] [android, 4.4.4, 10.0.3.15] ------------->sdkDir_2
[INFO] [android, 4.4.4, 10.0.3.15] {
"readonly": false,
"bubbleParent": true,
"writable": true,
"directoryListing": [],
"symbolicLink": false,
"apiName": "Ti.Filesystem.File",
"hidden": false,
"nativePath": "file:///storage/emulated/0/co.test.zone",
"executable": false,
"size": 4096,
"name": "co.happysoft.zone",
"parent": {
"readonly": false,
"bubbleParent": true,
"writable": true,
"directoryListing": [
"Music",
"Podcasts",
"Ringtones",
"Alarms",
"Notifications",
"Pictures",
"Movies",
"Download",
"DCIM",
"Android",
"storage",
...
[INFO] [android, 4.4.4, 10.0.3.15] ------------->downLoadDir
[INFO] [android, 4.4.4, 10.0.3.15] {
"readonly": true,
"bubbleParent": true,
"writable": false,
"directoryListing": [],
"symbolicLink": false,
"apiName": "Ti.Filesystem.File",
"hidden": false,
"nativePath": "file:///android_asset/Resources/api/Download",
"executable": false,
"size": 0,
"name": "/Download",
"parent": null
}
I'm so confused that how the Download path should changed and it's directoryListing has nothing. And, I'm wonder why the sdkDir_1 has nothing too. Anyone have a good solution to me, thanks in advance.
Solution
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:
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.
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?
Answered By - frank jorsn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.