使用Intents for samsung explorer打开指定的文件夹

时间:2014-04-23 19:17:46

标签: android android-intent

我可以打开我的文件应用程序,但我需要在我的文件中打开一个特定的文件夹。它显示了其他文件资源管理器的文件夹。以下是我从另一篇文章中获取的代码:

public void openFile(Uri data) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setDataAndType(data,"file/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

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 folder");
        chooserIntent.putExtra(Intent.EXTRA_STREAM,data.toString() );
    }
    else {
        chooserIntent = Intent.createChooser(intent, "Open file");
    }

    try {
        startActivity(chooserIntent);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getApplicationContext(), "No suitable File Manager was found.", Toast.LENGTH_SHORT).show();
    }
}

1 个答案:

答案 0 :(得分:0)

我使用它来使用我的文件应用程序打开特定文件夹:

Intent intent = new Intent();
        intent.setAction("com.sec.android.app.myfiles.VIEW");
        intent.putExtra("folderPath", Environment.getExternalStorageDirectory().getPath()+ "/myFolder/");
startActivity(intent);

希望它有所帮助。