我看到很多类似的问题,但没有人帮助我!
所以,我想获取可用文件管理器的列表,当用户选择时,在这个文件管理器中打开文件夹,其中有必要的文件。文件可以是任何扩展名。
我尝试这样:
s=Uri.fromFile(File object);
...
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("file/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setData(s);
context.startActivity(intent);
..但这会抛出ActivityNotFoundException。
请帮我。谢谢!
我StartActivity
从调用DialogInterface.OnClickListener
,我有函数,创建对话框并返回。还有一点,当我不这样做时setData
,程序正在工作并向用户提供文件管理器列表,但它是打开的根目录,而不是文件目录。
private Dialog createAlertDialog( final Context context, final Uri s) {
Dialog dialog = new Dialog(context);
Builder builder = new AlertDialog.Builder(context);
DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogArg, int which) {
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("file/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setData(s);
context.startActivity(intent);
}
};
DialogInterface.OnClickListener onCloseDialog = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogArg, int which) {
}
};
dialog = builder.setPositiveButton(MyApp.getCustomAppContext().getString(R.string.ok), onClickListener)
.setNegativeButton(MyApp.getCustomAppContext().getString(R.string.cancel), onCloseDialog)
.setMessage(MyApp.getCustomAppContext().getString(R.string.open_explorer))
.create();
return dialog;
}
在日志中我有这个:
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): android.content.ActivityNotFoundException: No Activity found to
handle Intent { act=android.intent.action.GET_CONTENT cat=[android.intent.category.OPENABLE]
dat=file:///toptoptop/Noize%20MC%20Bring-Bring-Bring.mp4 }
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at android.app.Instrumentation.checkStartActivityResult
(Instrumentation.java:1409)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at android.app.Instrumentation.execStartActivity
(Instrumentation.java:1379)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at android.app.Activity.startActivityForResult
(Activity.java:2827)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at android.app.Activity.startActivity(Activity.java:2933)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at com.serbinvitaly.copyeraser.ResultsActivity$4.onClick
(ResultsActivity.java:171)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at android.os.Handler.dispatchMessage(Handler.java:99)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at android.os.Looper.loop(Looper.java:123)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at android.app.ActivityThread.main(ActivityThread.java:3687)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at java.lang.reflect.Method.invokeNative(Native Method)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at java.lang.reflect.Method.invoke(Method.java:507)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
09-13 11:06:47.226: ERROR/AndroidRuntime(14534): at dalvik.system.NativeStart.main(Native Method)
09-13 11:06:47.226: WARN/ActivityManager(7260): Force finishing activity com.serbinvitaly.copyeraser/.ResultsActivity
09-13 11:06:47.230: ERROR/(7260): Dumpstate > /data/log/dumpstate_app_error