【问题标题】:How to detect Setaction in intent android? [duplicate]如何检测 Intent android 中的 Setaction? [复制]
【发布时间】:2018-02-03 07:42:54
【问题描述】:

我尝试使用 pdf 阅读器打开 pdf。 但我没有找到任何应​​用程序。

在显示消息之前如何找到可用的应用程序。

我只想在任何应用程序存在打开 pdf 文件的情况下打开应用程序弹出窗口,我该如何添加它?

Intent target = new Intent();
target.setType("application/pdf");
target.setData(Uri.parse(attachment));
target.setAction(Intent.ACTION_GET_CONTENT);
Intent intent = Intent.createChooser(target, "Open File");

【问题讨论】:

标签: android android-intent


【解决方案1】:

试试这个;

 Uri path = Uri.fromFile(file); 
 Intent intent = new Intent(Intent.ACTION_VIEW); 
 intent.setDataAndType(Uri.parse(attachment), "application/pdf"); 
 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

 try { 
      startActivity(intent); 
   }  
    catch (ActivityNotFoundException e) { 
       Toast.makeText(OpenPdf.this,  "No Application Available to View PDF",  
                        Toast.LENGTH_SHORT).show(); 
   } 

【讨论】:

  • 所以添加包后它只会在 adobe reader 中打开?@vishal-vaishnav
  • yaa 绝对...
  • 我希望打开任何可用的应用程序。如果没有可用的应用程序我想显示吐司不需要弹出如何添加它?@vishal-vaishnav
  • 我更新了答案..试试这个
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-08
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多