Android: proper intent-filter to indicate my application can open a filetype?
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:
- 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).
- 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
精彩评论