我的电子邮件中有附件。现在,一旦我点击附件,那么它应该在我的设备中使用我的特定App安装打开。我怎样才能实现这一目标?请帮忙
答案 0 :(得分:0)
将清单文件中的intent-filter添加到活动中。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.txt" />
</intent-filter>
然后在你的活动检查意图的onCreate()中:
Intent intent = getIntent();
if(Intent.ACTION_VIEW.equals(intent.getAction())){
// use getData(), etc...
String name = intent.getData().getPath();
}
您也可以查看this article。这是因为第三方应用程序与您的应用程序共享内容(不是&#34;打开&#34;),但它类似,可能有助于理解共享/开放的工作原理。