3
votes

I write a "application/vnd.wfa.wsc" record on a tag (NFC Handover wifi) record type. Now I want to start my application with a given activity which scans the tag.

I did the following :

I added this by writing the Tag:

NdefRecord.createApplicationRecord("at.nfc.wifi"); (the package name)

Now by scanning the tag, adb logcat shows me the following:

...
I/ActivityManager(  252): START {flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras) u=0} from pid 479
I/NfcDispatcher(  479): matched AAR to NDEF
W/IntentResolver(  252): resolveIntent failed: found match, but none with Intent.CATEGORY_DEFAULT
I/ActivityManager(  252): START {act=android.nfc.action.NDEF_DISCOVERED pkg=at.nfc.wifi (has extras) u=0} from pid 479
W/InputMethodManagerService(  252): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41877bf8 attribute=null

Here the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="at.nfc.wifi"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" />
    <uses-feature 
        android:name="android.hardware.nfc"
        android:required="true" />
    <uses-permission android:name="android.permission.NFC" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".activities.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
             <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <data android:mimeType="application/vnd.wfa.wsc" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".activities.NFCWriterActivity"></activity>
        <activity android:name=".activities.NFCReaderActivity"></activity>
        <activity android:name=".activities.WifiManagerActivity"></activity>
        <activity android:name=".activities.WifiConfiguratorActivity"></activity>
        <activity android:name=".activities.TagWriterOptionsActivity"></activity>
        <activity android:name=".activities.WifiScannerTagActivity"></activity>
        <activity android:name=".activities.WifiScannerActivity"></activity>

    </application>

</manifest>

The onresume function:

@Override
protected void onResume() {
    super.onResume();
    Intent intent = new Intent(this, this.getClass());
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    nfcAdapter.enableForegroundDispatch(this, pendingIntent, null, null);
}

So what I want is I scan the Tag, and then the at.nfc.wifi.activities.NFCReaderActivity should start.

First adb logcat says: W/IntentResolver( 252): resolveIntent failed: found match, but none with Intent.CATEGORY_DEFAULT what does this mean?

And second, can I match the application/vnd.wfa.wsc recordtype? or how can I do that, that my t.nfc.wifi.activities.NFCReaderActivity starts by scanning the Tag.

Thank you for hints :)


EDIT: Now my app starts with:

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

     <intent-filter>
        <action android:name="android.nfc.action.NDEF_DISCOVERED" />
        <action android:name="at.nfc.wifi.activities.NFCReaderActivity" />


       <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter>

Is it right that, if I want to start a subactivity not the main application, I have to check in the Launch-Activity for if (getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) and then start the one? And can I filter for this special application/wsc... record?

thx

1

1 Answers

0
votes

Simply remove the <action android:name="android.nfc.action.NDEF_DISCOVERED" /> from the first (original) intent filter. I think that should fix the matching for the "application/vnd.wfa.wsc" MIME type.

You should add the 2nd intent filter to the Activity declaration for the Activity that you would like to start when such an intent is received. So e.g. move it to the ".activities.NFCReaderActivity" section.