【发布时间】:2021-03-08 03:32:43
【问题描述】:
我需要在 Android 10 中打开一个特定文件夹,以便在我的应用中只能看到该文件夹中的文件。
我试过这个:
try {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
File f = new File(getExternalFilesDir(null) + "/MyFolder");
Uri uri = FileProvider.getUriForFile(getApplicationContext(),getApplicationContext().getPackageName()+".provider",f);
Toast.makeText(MainActivity.this,f.getPath(),Toast.LENGTH_LONG).show();
intent.setDataAndType(uri,"text/plain");
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
catch (Exception e) {
Log.d("Exception",e.toString());
Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG).show();
}
但是,它会打开整棵树。
我真正想要的是打开那个文件夹。文件夹中的文件应该可以被其他应用程序打开。任何帮助将不胜感激。
【问题讨论】:
-
The files in the folder should be openable by other apps.??你这是什么意思? -
so that only the files inside that folder can be seen in my app.不可能。用户始终可以浏览到所有其他位置。 -
不......我的意思是说我的应用程序应该只能打开 MyFolder 中的那些文本文件。
标签: android file directory android-10.0