Project Tango:将ADF导出到SD卡

时间:2014-12-16 06:19:31

标签: java android google-project-tango

我正在尝试将ADF从项目探戈导出到SD卡,使用来自文档的代码示例,并且它对我失败了。我能够通过正确的导出路径成功弹出导出对话框。但是,当我点击导出按钮时,我的日志失败

12-16 00:48:12.203      192-603/? E/tango_service_library_context﹕ bool RuntimeExportAreaDescription(const string&, const string&, const string&): Internal error occured opening file: /storage/emulated/0/c5617dae-01b0-4825-8ee1-777c17693414
12-16 00:48:12.209    8246-8246/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.projecttango.tango, PID: 8246
com.google.atap.tangoservice.TangoInvalidException
        at com.google.atap.tango.TangoInternal.throwTangoExceptionIfNeeded(TangoInternal.java:118)
        at com.google.atap.tango.TangoInternal.exportAreaDescriptionFile(TangoInternal.java:104)
        at com.google.atap.tango.RequestImportExportActivity.onExportAccepted(RequestImportExportActivity.java:83)
        at com.google.atap.tango.RequestImportExportDialog$1.onClick(RequestImportExportDialog.java:108)
        at android.view.View.performClick(View.java:4438)
        at android.view.View$PerformClick.run(View.java:18422)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5030)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)

我的应用程序具有对外部存储的读/写访问权限,我通过编写具有相同路径的文件进行了验证。

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

这是我的导出代码(取自探戈文档):

        adfToExport = GetAdfs().get(0);

        String externalStorageDirectory = Environment.getExternalStorageDirectory().toString();

        /* this was just a test to verify the app can write to the path
        try {
            String path = externalStorageDirectory + "/c5617dae-01b0-4825-8ee1-777c17693414";
            File file = new File(path);
            FileOutputStream fOut = new FileOutputStream(file);
            OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
            myOutWriter.append("testing 1 2 3");
            myOutWriter.close();
            fOut.close();
        } catch (Exception ex) {
            Log.e(LOG_TAG, "failed to write file: " + path, ex);
        }
        */

        Intent exportIntent = new Intent();
        exportIntent.setClassName(INTENT_CLASSPACKAGE, INTENT_IMPORTEXPORT_CLASSNAME);
        exportIntent.putExtra(EXTRA_KEY_SOURCEUUID, adfToExport);
        exportIntent.putExtra(EXTRA_KEY_DESTINATIONFILE, externalStorageDirectory);
        startActivityForResult(exportIntent, Tango.TANGO_INTENT_ACTIVITYCODE);

1 个答案:

答案 0 :(得分:3)

尝试使用以下代码对导出路径进行硬编码,而不是从Environment.getExternalStorageDirectory()获取外部存储路径:

String mapsFolder = "/sdcard/maps";
File file = new File(mapsFolder);

我将来自AreaLearningSample的代码修改为getAppsSpaceADFFolder()函数到下面,它对我来说很好。

private String getAppSpaceADFFolder() 
{
//  String mapsFolder = getFilesDir().getAbsolutePath() + File.separator + "Maps";
    String mapsFolder = "/sdcard/maps";
    File file = new File(mapsFolder);
    if (!file.exists()) {
        file.mkdirs();
    }
    return mapsFolder;
}

我还没弄清楚为什么Environment.getExternalStorageDirectory()不起作用并引发上述异常,我会在得到一些结果后编辑这个答案。