在Android中打开默认文件管理器外部内存?
我们的Android设备包含内部内存和外部内存。我们的应用程序包含一个打开的按钮。当我们单击此打开按钮以查看/打开默认文件管理器外部内存时 示例代码:在Android中打开默认文件管理器外部内存?,android,android-intent,Android,Android Intent,我们的Android设备包含内部内存和外部内存。我们的应用程序包含一个打开的按钮。当我们单击此打开按钮以查看/打开默认文件管理器外部内存时 示例代码: Intent intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); intent.setType("file/*"); startActivity(Intent.createChooser(intent, "View Default F
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivity(Intent.createChooser(intent, "View Default File Manager"));
此代码可以在默认文件管理器内部内存中查看/打开
如何(单击打开按钮)查看/打开默认文件管理器外部内存
可能吗?试试这个代码
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/file");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),”application/file”);
startActivity(intent);
类内定义:
public static String SDCARD_DIRECTORY;
public static String REPORTS_DIRECTORY;
在onCreate中:
File sdCard = Environment.getExternalStorageDirectory();
SDCARD_DIRECTORY = sdCard.getAbsolutePath();
REPORTS_DIRECTORY = SDCARD_DIRECTORY + "/MyReports";
// Create if necessary the desired folder
File directory = new File (REPORTS_DIRECTORY);
directory.mkdirs();
现在,这个代码对我有效
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
File file = new File(REPORTS_DIRECTORY);
intent.setDataAndType(Uri.fromFile(file),"application/file");
StartActivityForResult(Intent.createChooser(intent,"Open folder"), 0);
维什瓦感谢您的回复。不幸的是,这段代码不适合我。