use*_*095 14 file-extension android intentfilter
我需要创建打开文件管理器的意图(如果已安装),并且我希望文件管理器只向用户显示txt文件,因此用户无法选择具有错误扩展名的文件.
private static final int FILE_SELECT_CODE = 0;
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select txt file"),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(this.getActivity(), "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == Activity.RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
String path = uri.getPath();
input = new File(path);
try {
txtParser = new TxtFileParser(input);
} catch (FileNotFoundException e) {
/* Exception handler must be here! */
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
Run Code Online (Sandbox Code Playgroud)
我设法做到了这一点.但我不知道如何定义txt扩展.
Com*_*are 14
我希望文件管理器只向用户显示txt文件,因此用户无法选择扩展名错误的文件
这根本不可能.欢迎您使用MIME类型text/plain代替*/*,但是:
.txt扩展名的文件ACTION_GET_CONTENT该MIME类型的应用程序| 归档时间: |
|
| 查看次数: |
6382 次 |
| 最近记录: |