遇到问题摆脱Android模拟器中的文件(二) [英] Having trouble to get the files from android emulator (Titanium)

查看:339
本文介绍了遇到问题摆脱Android模拟器中的文件(二)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

家伙!我有麻烦从我的Andr​​oid模拟器中获取文件!

guys! I have trouble to get files from my android emulator!

①这里是我的模拟器信息:
Genymotion供个人使用的 - 三星Galaxy Note 3 - 4.4.4 - API 19 - 1080x1920

① 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:

我已经存储在内部存储测试两款MP3文件目录,路径为 /存储/模拟/ 0 /下载

正如你可以看到,这两个MP3文件在 下载目录。我的问题是我永远无法得到这两个文件正确的道路。

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.

③这是我的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());
    ...

和这里是控制台:

[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
  }

我很困惑的是如何在 下载路径应该改变它的 Directory上市无关。而且,我不知道为什么在 sdkDir_1 有没有什么太。任何人有一个很好的解决方案给我,先谢谢了。

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.

推荐答案

好了,感谢 @Fokke的Zandbergen 这么多,让我想起我犯了一个错误,试图通过让仿真器的内部文件外部存储目录即可。而现在,很明显,如果你想从模拟器获得本地文件或真正的移动设备,也许后续的建议可以帮助你:

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:

①从模拟器获得本地文件

1 的Andr​​oid ,尝试这个路径:的file:///存储/模拟/ 0

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

首先,目录模拟只是针对特殊的模拟器,所有的Andr​​oid模拟器有这个目录。然后,目录 0 是指你的模拟器只能有一个内部的存储目录,原因是有没有外部存储 SD卡作为模拟器。

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 ,试试这个路径: /Users/xxx/Library/Developer/CoreSimulator/Devices/F34851D0-AFA5-443E-AEF6-70B695FB9C5E/data

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

有关目录 F34851D0-AFA5-443E-AEF6-70B695FB9C5E ,它的仿真ID,您可以通过 TI资讯命令来检查

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

②从获取真正的移动设备的本地文件

1 的Andr​​oid ,尝试这个路径:的file:///存储/ sdcard0

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

请注意这一点, sdcard0 为您的移动设备的内部存储。如果你需要从外部存储目录中获取本地文件,也意味着 SD卡,那么你应该试试这个方法:

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 ,导致iPhone没有外部存储,所以它同样到模拟器。嗯,我还没有测试这种方式,也许你应该试试。

[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.

好,大家好,我最近测试了真正的移动设备文件路径,我的意思是文件路径的 SD卡(外部存储)。然而,有一个不好的消息,我应该告诉你,方法钛API 得起检测,如果外部存储的存在是不是很好用。以下是详细信息:

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. 如果(Ti.Filesystem.isExternalStorage present())总是返回true,虽然,在 SD卡别ŧpresent。

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

我推测,以 内部存储的今天,几乎所有的智能手机都内置嵌入(从不意味着智能手机的自我存储喜欢的电话簿,我的意思是的的内部存储的是一个特殊的外部存储,但嵌入到智能手机),和SD卡是扩大存储,但他们​​是一样的。

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

在我的测试中,当智能手机来自 HUAWEI 外部存储路径成为: 的file:///存储/ sdcard1 ,尊贵与内部存储的 sdcard0

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

然而,当制造商的三星,外部存储路径是:文件:///存储/ extSdCard

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?

这篇关于遇到问题摆脱Android模拟器中的文件(二)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆