开发者

Android: proper intent-filter to indicate my application can open a filetype?

开发者 https://www.devze.com 2023-02-11 08:54 出处:网络
I am trying to configure my manifest file to indicate my application can open PDF files.The below configuration works, but it gives some funny behavior with the emulator:

I am trying to configure my manifest file to indicate my application can open PDF files. The below configuration works, but it gives some funny behavior with the emulator:

  1. When the "view" action is present, my application is not started on install (when I run from Eclipse, the application gets installed on the emulator, but it does not start automatically).
  2. When application/pdf is present, after running from eclipse the application doesn't show up in my emulator's application menu.

(I don't see either of these issues if my only intents are "main" and "launcher")

 <intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:mimeType="application/pdf" /> 
 </intent-filter>

EDIT: Okay, I was a little confused about intents. The solution to my above issues is to have 2 different intent-filters, as shown below.

However, I do have a second question. Android successfully launches my app for PDF files, but when it launches onCreate(bundle) is calle开发者_StackOverflow社区d and not startActivity(Intent). How should I get the intent data?

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="application/pdf" /> 
</intent-filter>


In your Activity, you can use getIntent() to get the intent used to start it.


startIntent() is not a callback. Its a method for you to call in order to launch another intent.

When your Activity is launched, you will get your onStart() (and onCreate, just before that), called, and from there you call getIntent() to re

0

精彩评论

暂无评论...
验证码 换一张
取 消