2

我尝试测试一个用作 ssh 客户端的应用程序。因此,我们现在使用位于 android 设备存储中的私钥。要连接到 ssh 服务器,用户在文件对话框中选择密钥。

如何将文件传输到 ARC 文件系统以在由 ARCwelder 启动的应用程序中使用

我尝试了有关 Accessing ExternalStorage 的帖子中建议的解决方案,但即使启用了 Experimental developer options 我也无法弄清楚第七步(“单击弹出窗口左侧列出的'Experiments'选项卡。这仅在以下情况下可见您完全启用了实验功能。”),因为没有“实验”选项。


由于我使用的注释Intent.ACTION_GET_CONTENT而不是 aFileDialog。我更进一步。现在我在 ARC 中有 android 文件对话框。但是,我无法选择除 txt-files.x 以外的文件,我也尝试过"intent.setType(*/*)"如本文所述。

private void activity_android_open(View view) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("file/*");
    startActivityForResult(intent, 0);
}

我可以使用以下方法(从此处)选择密钥并在我的 android 设备上获取文件路径。但是,当使用 ARC 时,我可以从我的卷中选择文件,但 filePath 是空的。祝酒词在我的 android 设备上显示正确的文件位置。然而,在焊机中,字符串是空的。

/**
 * 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
4

1 回答 1

1

ChomeOs/ARC 正在“运行” Kitkat,因此您可以使用 Android 存储访问框架来获取文件。

这将使您开始:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
activity.startActivityForResult(intent, 1);
于 2015-05-01T21:30:31.817 回答