LoginSignup
2
1

More than 5 years have passed since last update.

NDEFフォーマットのタグからIDを読む

Posted at
Activity.java
@Override
public void onCreate() {
    TextView textView = (TextView)findViewById(R.id.tag_id);
    String action = getIntent().getAction();
    if(NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
        byte[] extraId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
        textView.setText(extraId.toString());
    }
}

ACTION_NDEF_DISCOVEREDインテントをフィルタする場合(text/plainのMIMEタイプを付加)

AndroidManifest.xml
    <uses-feature android:required="true" android:name="android.hardware.nfc" />
    <uses-permission android:name="android.permission.NFC" />

    <application
        ...
        <activity
            ...
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mineType="text/plain" />
            </intent-filter>
        </activity>
    </application>

ACTION_NDEF_DISCOVEREDインテントをフィルタする場合(URIに対して)

AndroidManifest.xml
<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http"
            android:host="developer.android.com"
            android:pathPrefix="/index.html" />
</intent-filter>
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1