在Google Chrome ARC应用中添加和访问文件

时间:2015-04-18 17:20:55

标签: google-chrome-arc

我尝试测试一个充当ssh客户端的应用。因此,我们在Android设备上的存储中使用私钥。要连接到ssh服务器,用户在文件对话框中选择密钥。

如何将文件传输到ARC文件系统,以便在ARC welder启动的应用中使用它?

我尝试了post about Accessing ExternalStorage中建议的解决方案,但即使启用了实验性开发人员选项,我也无法找到第七步("点击'实验'标签上列出的弹出窗口的左侧。只有在您启用了实验性功能时才能看到这一点。"),因为没有"实验"选项。


由于评论我使用Intent.ACTION_GET_CONTENT而不是aFileDialog。我更进了一步。现在我在ARC中有了android文件对话框。 但是,我无法选择txt-files.x以外的文件。我也尝试了post中提到的"intent.setType(*/*)"

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

<击>

我可以使用以下方法(来自here)选择密钥并在我的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

0 个答案:

没有答案