我使用下面的代码,允许用户从三星Android设备访问我的文件。我想在我的文件打开某些路径,当用户按下按钮。现在,它会打开默认的路径。你能告诉我,如果有可能从Android通过传递路径时打开文件?下面是我使用的代码。你能给我将打开我的文件到某个路径的代码?预先感谢您的帮助。
public void AccessingFiles(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
// special intent for Samsung file manager
Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
// if you want any file type, you can skip next line
sIntent.putExtra("CONTENT_TYPE", "*/*");
sIntent.addCategory(Intent.CATEGORY_DEFAULT);
Intent chooserIntent;
if (getPackageManager().resolveActivity(sIntent, 0) != null){
// it is device with samsung file manager
chooserIntent = Intent.createChooser(sIntent, "Open file");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent});
}
else {
chooserIntent = Intent.createChooser(intent, "Open file");
}
try {
startActivityForResult(chooserIntent, CHOOSE_FILE_REQUESTCODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getApplicationContext(), "No suitable File Manager was found.", Toast.LENGTH_SHORT).show();
}
}
为寻找解决同样的问题,这是我打开我的文件指出,在一定的路径:
File folder = new File(""); // construct the path
Intent fmIntent = new Intent(Intent.ACTION_MAIN);
fmIntent.setComponent(new ComponentName("com.sec.android.app.myfiles", "com.sec.android.app.myfiles.MainActivity"));
fmIntent.setData(Uri.parse(folder.toString()));
要注意的是fmIntent.setData(Uri.fromFile(folder))
没有为我工作。
该解决方案与我的文件1.19.0测试,这是我来到它: