【问题标题】:How manage "No application can perform this action" (AKA ActivityNotFoundException)如何管理“没有应用程序可以执行此操作”(AKA ActivityNotFoundException)
【发布时间】:2013-08-10 04:12:21
【问题描述】:

这是我的代码

    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 市场并搜索任何应用程序..

但是,我不知道为什么,我的代码从来没有遇到异常,只是显示一个对话框,上面写着“没有应用程序可以执行此操作”。我该如何管理和实现我的目标?

【问题讨论】:

    标签: android android-intent activitynotfoundexception


    【解决方案1】:

    尝试摆脱createChooser()。毕竟,ACTION_VIEW 无论如何都不需要这样做——如果用户为此 MIME 类型选择了默认值,请允许他们使用它。而且,选择器会阻止您获得ActivityNotFoundException,因为选择器 是活动,并且它始终存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多