ab11
ab11

Reputation: 20090

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:

  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 called 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>

Upvotes: 4

Views: 1515

Answers (2)

dtr2
dtr2

Reputation: 172

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

Upvotes: 0

nEx.Software
nEx.Software

Reputation: 6862

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

Upvotes: 3

Related Questions