gpt4 book ai didi

java - 探戈项目 : Export ADF to sdcard

转载 作者:行者123 更新时间:2023-11-29 05:13:18 25 4
gpt4 key购买 nike

我正在尝试使用文档中的代码示例将 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>

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

        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);

最佳答案

尝试使用下面的代码对导出路径进行硬编码,而不是从 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() 不起作用并抛出上述异常,一旦我得到一些结果,我将编辑这个答案。

关于java - 探戈项目 : Export ADF to sdcard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27498672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com