所以这是我的代码
public void onClick() {
try {
startActivity(Utils.openFile(f.getPath(),myExt));
}
catch(ActivityNotFoundException activityNotFoundException) {
Toast.makeText(mContext, "Nessuna App trovata", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q="+myExt+"&c=apps"));
startActivity(intent);
}
我的 Utils.openfile() 在哪里
public static Intent openFile(String u,String b) {
File file = new File(u);
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file),"application/" + b);
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Apri File");
return intent;
}
现在如您所见,我想管理如果找不到任何可以打开我的文件(pdf、mobi 或 epub)的应用程序,我想开始一个意图链接到 android 市场并搜索任何应用程序..
但是,我不知道为什么,我的代码永远不会遇到异常,只是显示一个对话框,上面写着“没有应用程序可以执行此操作”。我该如何管理和实现我的目标?