Launch activity with NFC

552 Views Asked by At

I'm trying to figure out how to launch a specific activity when an android device is subjected to an nfc-card with an application record in the ndef message. The activity I'm trying to launch is not the parent activity, which might be the cause of my issues...

The nfc cards are written with an ndef message containing two records, the first one is a URI record with a uri like "http://com.neodarque.nfc/item/52312321", and this is followed by an application record (created with NdefRecord.createApplicationRecord("com.neodarque.nfc"))

Relevant parts from the AndroidManifest.xml file:

<activity
    android:name="com.neodarque.nfc.activities.LoginActivity"
    android:label="@string/app_name"
    android:windowSoftInputMode="adjustResize|stateVisible" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>
<activity
    android:name="com.neodarque.nfc.activities.MainActivity"
    android:label="@string/title_activity_main"
    android:parentActivityName="com.neodarque.nfc.activities.LoginActivity" >
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.neodarque.nfc.activities.LoginActivity" />
    <intent-filter>
        <action android:name="android.nfc.action.NDEF_DISCOVERED" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:scheme="vnd.android.nfc"
            android:host="ext"
            android:pathPrefix="/com.neodarque.nfc:pkg"/>
    </intent-filter>
</activity>

I've also tried variants of the above with different android:pathPrefixes, with and without prefixing it with a slash, with and without trailing ":pkg".

And I've also tried using an intent filter for the uri-record instead, with no luck, like so:

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:scheme="http" android:host="nfc.neodarque.com"/>
</intent-filter>

My app is always launched when the device gets close to my nfc cards, but it is however always my LoginActivity that is launched by that action. What am I missing?

0

There are 0 best solutions below