I try to test an app that works as a ssh client. Therefore we use a private key at the moment that is located in the storage on the android device. To connect to the ssh server, the user chooses the key in a file dialog.
How can I transfer a file into the ARC file system to use it in an app started by ARC welder ?
I tried the solution suggested in post about Accessing ExternalStorage, but even with Experimental developer options enabled I was not able to figure out the seventh step ("Click the 'Experiments' tab listed on the left side of the popup. This is only visible if you enabled the experimental features at all."), because there is no "Experimental" option.
Because of the comments I use Intent.ACTION_GET_CONTENT
instead of aFileDialog. I am a step further. Now I have the android file dialog in ARC. However, I am not able to pick files other than txt-files.x I also tried "intent.setType(*/*)"
as mentioned in this post.
private void activity_android_open(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, 0);
}
I am able to pick the key and get the file path on my android device with the following methods (from here). However, when using ARC, I am able to pick the files from my volume, but the filePath is empty. The toasts show the right file location on my android device. In welder, however, the string is empty.
/**
* 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();
}
When I use chrome://inspect/#apps
to see the log, I get the error
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