我在标签(NFC Handover wifi)记录类型上写了“application/vnd.wfa.wsc”记录。现在我想用一个扫描标签的给定活动来启动我的应用程序。
我做了以下事情:
我通过编写标签添加了这个:
NdefRecord.createApplicationRecord("at.nfc.wifi");
(包名)
现在通过扫描标签,adb logcat 向我显示以下内容:
...
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
这里的清单:
<?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>
恢复功能:
@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);
}
所以我想要的是我扫描标签,然后 at.nfc.wifi.activities.NFCReaderActivity 应该启动。
首先 adb logcat 说: W/IntentResolver(252): resolveIntent failed: found match, but none with Intent.CATEGORY_DEFAULT 这是什么意思?
其次,我可以匹配 application/vnd.wfa.wsc 记录类型吗?或者我该怎么做,我的 t.nfc.wifi.activities.NFCReaderActivity 从扫描标签开始。
谢谢你的提示:)
编辑:现在我的应用程序开始于:
<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>
是否正确,如果我想启动一个子活动而不是主应用程序,我必须在 Launch-Activity 中检查 if (getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) 然后启动一个?我可以过滤这个特殊的应用程序/wsc... 记录吗?
谢谢