1
앱의 버튼을 클릭 할 때 NFC 태그를 읽으려고합니다. 현재 기본 모드 (Nexus 휴대 전화에 설치된 태그 앱)에서 태그를 감지 할 수 있습니다. 하지만 난 내 태그 시작하려는 통해 활동 선택기를 표시 얻을 수 아니다Android NFC 시작 화면
public class NFC_button extends Activity
{
protected IntentFilter ifilter ;
private NfcAdapter adapter;
private BroadcastReceiver receiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
if(NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction()))
{
Parcelable[] messages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage[] ndefmessages;
if(messages != null)
{
ndefmessages = new NdefMessage[messages.length];
for(int i = 0;i<messages.length;i++)
{
ndefmessages[i] = (NdefMessage)messages[i];
}
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
adapter=NfcAdapter.getDefaultAdapter(this);
ifilter = new IntentFilter();
ifilter.addAction("android.nfc.action.NDEF_DISCOVERED");
ifilter.addCategory("android.intent.category.LAUNCHER");
}
@Override
protected void onResume() {
registerReceiver(receiver, ifilter);
super.onResume();
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nfc.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.NFC"/>
<uses-feature android:name="android.hardware.nfc" android:required="true"/>
<uses-sdk android:minSdkVersion="10"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".NFC_ExampleActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NFC_button">
</activity>
</application>
나는 BroadcastReciver을 생각하지 않는이 태그를 읽을 수있는 올바른 방법 모두의
왜 BroadcastReceiver가 태그를 읽는 올바른 방법이라고 생각하지 않았는지 설명 할 수 있습니까? 내 유스 케이스를 고려해보십시오. 태그에 데이터를 쓰고 있습니다. 사용자가 데이터를 준비한 다음 태그가 감지되면 데이터를 쓸 장치의 가까이에 태그를 놓으십시오. 사용자가 다른 활동을하고있어 데이터를 쓸 준비가되기 때문에 활동을 시작하고 싶지 않습니다 (UI 변경). – wsgeorge