【发布时间】:2015-06-25 13:24:42
【问题描述】:
我尝试测试一个可用作 ssh 客户端的应用。因此,我们现在使用位于 android 设备存储中的私钥。要连接到 ssh 服务器,用户在文件对话框中选择密钥。
如何将文件传输到 ARC 文件系统中,以便在 ARC welder 启动的应用中使用它?
我尝试了post about Accessing ExternalStorage 中建议的解决方案,但即使启用了实验开发人员选项,我也无法弄清楚第七步(“单击弹出窗口左侧列出的“实验”选项卡。这只是如果您完全启用了实验功能,则可见。”),因为没有“实验”选项。
因为 cmets,我使用 Intent.ACTION_GET_CONTENT 而不是 aFileDialog。我更进一步。现在我在 ARC 中有 android 文件对话框。 但是,我无法选择除 txt-files.x 以外的文件
private void activity_android_open(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, 0);
}
我可以通过以下方法(来自here)在我的安卓设备上选择密钥并获取文件路径。但是,当使用 ARC 时,我可以从我的卷中选择文件,但 filePath 是空的。祝酒词在我的 android 设备上显示正确的文件位置。但是在welder 中,字符串是空的。
/**
* Opens file dialog to choose RSA key???
* @param view The current view, here the button pressed.
*/
public void activity_simple_open(View view){
// see https://stackoverflow.com/questions/29425408/local-file-access-on-google-chrome-arc/29426331#29426331
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode==RESULT_OK){
Uri uri = data.getData();
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
filePath = Environment.getExternalStorageDirectory() + "/" + split[1];
}
// TODO handle non-primary volumes
}
}
showToast(filePath);
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString(getString(R.string.prefKey_privKeyFilePath), filePath);
editor.commit();
}
private void showToast(String message){
Toast toast = Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG);
toast.show();
}
当我使用chrome://inspect/#apps 查看日志时,我得到了错误
Uncaught (in promise)
TypeError: Cannot read property 'retainKey' of undefined {stack: (...), message: "Cannot read property 'retainKey' of undefined"} message: "Cannot read property 'retainKey' of undefined"
stack: "TypeError: Cannot read property 'retainKey' of undefined↵ at chrome-extension://adhppmdiaclmoepimdhlkdelgabmhdlf/_modules/mfaihdlpglflfgpfjcifdjdjcckigekc/gen_index.min.js:67:114"get stack: function () { [native code] }arguments: nullcaller: nulllength: 0name: ""prototype: StackTraceGetterconstructor: function () { [native code] }__proto__: Object__proto__: function Empty() {}apply: function apply() { [native code] }arguments: nullbind: function bind() { [native code] }call: function call() { [native code] }caller: nullconstructor: function Function() { [native code] }length: 0name: "Empty"toString: function toString() { [native code] }__proto__: Object<function scope><function scope>No Scopesset stack: function () { [native code] }__proto__: Error(anonymous function) @ filesystem.js:546
【问题讨论】:
-
使用
ACTION_GET_CONTENT调出 Chrome OS Files 应用程序。 -
@CommonsWare 我使用 aFileDialog 库。好像没问题。但是,我看到了 android 系统通常的文件结构。但是如何向该结构添加外部内容或如何访问外部文件?我需要 rsa 密钥...
-
"如何访问外部文件?" -- 正如我所写,使用
ACTION_GET_CONTENT来调出Chrome OS Files 应用程序。遵循您链接到的那些说明可能毫无意义,因为即使您愿意,用户 也不会这样做。用户会期望从他们的 Chrome OS 机器上挑选一个文件,因为这是他们所有其他 Chrome OS 应用程序都会这样做的方式。据我所知,在 ARC 中执行此操作的唯一方法是使用ACTION_GET_CONTENT来启动 Chrome OS Files 应用程序。 -
我不认为这是重复的。现在,本地文件访问原则上可以使用 ACTION_GET_CONTENT。但是,我想使用 ssh 私钥。使用 android 上的外部应用程序(oi 文件管理器)或插件(aFileManager)可以完成此操作。但是,我看不到如何使用 ACTION_GET_CONTENT 来完成它,因为私钥不可选择。