如何在三星的Android我的文件编程方式打开某些路径

问题描述 投票:3回答:1

我使用下面的代码,允许用户从三星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();
    }
}
android
1个回答
0
投票

为寻找解决同样的问题,这是我打开我的文件指出,在一定的路径:

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测试,这是我来到它:

  1. 我创建了一个自定义启动;
  2. 我的文件可以创建主屏幕快捷方式到特定的路径;
  3. 当安装快捷意图被送到我启动我甩了它的内容,这样我可以用它从上面的代码片断创建我的fmIntent。
© www.soinside.com 2019 - 2024. All rights reserved.