想做一个手机NFC的读卡程序,之前是在Manifest里面写的intent-filter,程序能够正常运行,当卡片靠近手机,NFC能够感应到卡片的存在,并打开NFCView .java。这是代码<activity android:name=".NFCView">
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/filter_nfc"
/>
</activity>但是现在我希望把Intent-Filter改写在java代码中,使得只有在程序打开后才能进行NFC的感应。但是更改后程序不能识别卡片了,不知道是不是我的代码有问题,请大家看一看
这是更改后的Manifest:<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/filter_nfc"
/> 这是java代码BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
intent = new Intent(NFCActivity.this, NFCView.class);
startActivity(intent);
}
};
IntentFilter filter = new IntentFilter();
filter.addAction("android.nfc.action.TECH_DISCOVERED");
registerReceiver(mReceiver, filter);请问这是什么原因啊,应该怎么改呢,我就想实现打开程序后,当有数据卡片靠近手机后,NFC能够感应到,然后打开我的NFCView .java就行了
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/filter_nfc"
/>
</activity>但是现在我希望把Intent-Filter改写在java代码中,使得只有在程序打开后才能进行NFC的感应。但是更改后程序不能识别卡片了,不知道是不是我的代码有问题,请大家看一看
这是更改后的Manifest:<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/filter_nfc"
/> 这是java代码BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
intent = new Intent(NFCActivity.this, NFCView.class);
startActivity(intent);
}
};
IntentFilter filter = new IntentFilter();
filter.addAction("android.nfc.action.TECH_DISCOVERED");
registerReceiver(mReceiver, filter);请问这是什么原因啊,应该怎么改呢,我就想实现打开程序后,当有数据卡片靠近手机后,NFC能够感应到,然后打开我的NFCView .java就行了
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
应该去掉吧,不然不知道响应哪一个啊