我试图打开官方文件管理器应用程序(三星的com.sec.android.app.myfiles(,我使用以下代码:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
//intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);// even this does not work
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
此代码在我的三星Galaxy中启动DropBox应用程序。我需要三星(com.sec.android.app.myfiles(、索尼、LG、华为、Oppo、小米、Htc等著名设备的文件管理器的包名列表。。因此,我可以按包名称启动文件管理器。
首先,您必须在运行时授予写入权限。并在写权限调用成功的情况下调用下面的方法。请参阅以获得运行时权限。
private static final int FILE_SELECT_CODE = 100;
/**
* Implicit intent for opening files on the device.
*/
private void openFileChooser() {
final Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
fileIntent.setType("*/*");
fileIntent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(fileIntent, "Select a File to Upload"), FILE_SELECT_CODE);
}
一切顺利。