Android Beam ã®åºæ¬
ãã®è¨äºã¯ Android Developers サイトã® Android 4.0 Platform ã®ä¸é¨åã³ NFC Basics/Beaming NDEF Messages to Other Devices ã®ç¿»è¨³ãã¾ã¨ãããã®ã§ãã
Android Beam ã¨ã¯
Android Beam 㯠NFC ãã¼ã¹ã®æ©è½ã§ãNFC ãå©ç¨å¯è½ãªæºå¸¯ç«¯æ«ãéãããã¨ã«ãã£ã¦ãã¦ã¼ã¶ã使ç¨ãã¦ããã¢ããªã«é¢ããæ å ±ãå³åº§ã«å ±æããæ©è½ã§ããç¯å²å ã«ããã¤ã¹ãåå¨ããæã¼æ°ã»ã³ãã¡ã¼ãã«ä»¥å ã§ã¼ã·ã¹ãã 㯠NFC æ¥ç¶ãæºåããå ±æã®ããã® UI ã表示ãã¾ããè¦ã¦ããä½ããä»ã®ããã¤ã¹ã¨å ±æããã«ã¯ãã¦ã¼ã¶ã¯ã¹ã¯ãªã¼ã³ããã ã¿ããããã ãã§ãã
éçºè
ã«ã¨ã£ã¦ãAndroid Beam ã¯æ®ã©å
¨ã¦ã®ã¿ã¤ãã®ãæ¥è¿ã«åºã¥ããã¤ã³ã¿ã©ã¯ã·ã§ã³ãå¼ãèµ·ããæ°ããæ¹æ³ã§ããä¾ãã°ãã¦ã¼ã¶ã¯é£çµ¡å¸³ãå³åº§ã«äº¤æããã«ããã¬ã¤ã¤ã¼ã®ã²ã¼ã ã®ã»ããã¢ããããã£ããããã¬ãé»è©±ã¸ã®åå ãåçããããªã®å
±æããªã©ãè¡ããã¨ãã§ãã¾ããã·ã¹ãã ã¯ä½ã¬ãã«ã® NFC ãµãã¼ã㨠å
±æã®UI ãæä¾ããä¸æ¹ããã©ã¢ã°ã©ã¦ã³ãã®ã¢ããªã¯ä»ã®ããã¤ã¹ã«è»¢éããããã®è»½éã®ãã¼ã¿ãæä¾ãã¾ããéçºè
ã¯å
±æããããã¼ã¿ã¨ãããã©ã®ããã«åãæ±ããããã«ã¤ãã¦ãå®å
¨ã«å¶å¾¡ãã¦ãããããæ®ã©ã®ã¤ã³ã¿ã©ã¯ã·ã§ã³ãå¯è½ã§ãã
ãã£ã¨å¤§ããªãã¤ãã¼ãã«ã¤ãã¦ã¯ãAndroid Beam ãååã®æ¥ç¶ã¨ãã¦å©ç¨ããã¦ã¼ã¶ããã¢ãªã³ã°ãæèããå¿
è¦ãªãBluetoothçµç±ã§ãã¼ã¿ã転éãããã¨ãã§ãã¾ãã
éçºè ã Android Beam ã«åºã¥ãã¤ã³ã¿ã©ã¯ã·ã§ã³ã«æãå ããªãã¦ããAndroid ã®ä¸ã«æ·±ãçµ±åãããå©çã享åãããã¨ãã§ããå ´åãããã¾ããããã©ã«ãã§ã¯ã·ã¹ãã 㯠ã¢ããªã±ã¼ã·ã§ã³ã® Android Market ã®URL ãå ±æãã¾ãããã®ãããã¦ã¼ã¶ã¯ããã«ã¢ããªã±ã¼ã·ã§ã³ã®ãã¦ã³ãã¼ãã¾ãã¯è³¼å ¥ãããã¨ãç°¡åã«ã§ãã¾ãã
Android Beam (NDEF Push with NFC)ã®ä»çµã¿
Android Beam 㯠ããããã¤ã¹ããä»ã¸ NDEF ã¡ãã»ã¼ã¸ãéä¿¡ãããã¨ï¼ãã®å¦ç㯠"NDEFããã·ã¥" ã¨ãã¦ãç¥ããã¦ãã¾ãï¼ãå¯è½ã¨ããæ°ãã NFC ã®æ©è½ã§ããAndroid Beam ããµãã¼ããã2å°ã® Android ããã¤ã¹ãé£æ¥ï¼ç´4cmï¼ããé常ã¯èé¢å士ãã¿ãããã¦ããæããã¼ã¿è»¢éã¯åæåããã¾ããNDEF ã¡ãã»ã¼ã¸ã®ä¸ã®ãã¼ã¿ã¯ãããã¤ã¹éã§å
±æããããã¼ã¿ãå«ããã¨ãã§ãã¾ããä¾ãã°ãé£çµ¡å¸³ã®å
±æãYouTubeã®å
±æãããªããã©ã¦ã¶ã«ããURLã®å
±æãè¡ãã¢ããªã¯ Android Beam ã使ãã¾ãã
Android Beam ã使ã£ãããã¤ã¹éã®ãã¼ã¿ã®éä¿¡ã«ã¯ãã¢ã¯ãã£ããã£ããã©ã¢ã°ã©ã¦ã³ãã«ããéã«ãå
±æãããæ
å ±ãå«ã NdefMessage ãçæããå¿
è¦ãããã¾ãã次ã®2ã¤ã®æ¹æ³ã®ãã¡ã®ããããã§ã·ã¹ãã ã«å¯¾ã㦠NdefMessage ã渡ãå¿
è¦ãããã¾ãï¼
- ã¢ã¯ãã£ããã£ä¸ã§ããã·ã¥ãã åä¸ã® NdefMessage ã®å®ç¾©ï¼
- ã¡ãã»ã¼ã¸ãéãããæã«é½åº¦ setNdefPushMessage() ãå¼ã³åºãã¾ããä¾ãã°ããããããã¢ã¯ãã£ããã£ã® onCreate() ã¡ã½ããã§ãã®ã¡ã½ãããå¼ã³åºãã¦ãNdefMessage ã渡ããã¨ã§ããããã¢ã¯ãã£ããã£ããã©ã¢ã°ã©ã¦ã³ãã«ããéã Android Beam ãä»ã®ããã¤ã¹ããæ´»æ§åãããå ´åã¯å¸¸ã«ãã·ã¹ãã 㯠NdefMessage ãä»ã®ããã¤ã¹ã«éä¿¡ãã¾ãã
- Android Beam ã®åæåã¨åæã«ããã·ã¥ãã NdefMessage ã®å®ç¾©ï¼
- éããã NdefMessage ãè¿ã createNdefMessage() ã¡ã½ããã®å®è£ ä¸ã«ãNfcAdapter.CreateNdefMessageCallback ãå®è£ ããããã®æãNfcAdapter.CreateNdefMessageCallback ã setNdefPushMessageCallback() ã®å®è£ ã¸æ¸¡ãã¾ãã
- ãã®ã±ã¼ã¹ã§ã¯ã¢ã¯ãã£ããã£ããã©ã¢ã°ã©ã¦ã³ãã«ããéãä»ã®ããã¤ã¹ããæ´»æ§åãããæãã·ã¹ãã ã¯éããã NdefMessage ãå¼ãåºãããã« createNdefMessage() ãå¼ã³åºãã¾ããããã¯ãã¡ãã»ã¼ã¸ã®ã³ã³ãã³ããã¢ã¯ãã£ããã£ã®åå¨ä¸ã«çµå§å¤åãããããããªãã±ã¼ã¹ã«ããã¦ãåæåããã Android Beam ãä¸åº¦ã ãé ä¿¡ããããã« NdefMessage ãå®ç¾©ãããã¨ã許ãã¾ãã
ã·ã¹ãã ã«ãã£ã¦ä»ã®ããã¤ã¹ã¸ã® NDEF ã¡ãã»ã¼ã¸ã®éä¿¡ã«æåããéã«ãç¹å®ã®ã³ã¼ããå¦çãããå ´åã¯ãNfcAdapter.OnNdefPushCompleteCallback ãå®è£ ããsetNdefPushCompleteCallback() ã§ã»ãããããã¨ãã§ãã¾ããã¡ãã»ã¼ã¸ãé ä¿¡ãããæãã·ã¹ãã 㯠onNdefPushComplete() ãå¼ã³åºãã§ãããã
ããã¤ã¹ã®åä¿¡æãé常㮠NFC ã¿ã°ã¨åçã®æ¹æ³ã§ NDEF ããã·ã¥ã¡ãã»ã¼ã¸ãå¦çãã¾ãã
ã·ã¹ãã ã¯ã¢ã¯ãã£ããã£ãéå§ããããã«ãACTION_NDEF_DISCOVERED ã¢ã¯ã·ã§ã³ã¨NdefMessage ã® æåã® NdefRecord ã«å¾ã£ã¦ URL ã MIME ã¿ã¤ãã®ãããããè¨å®ãã¦ãã¤ã³ãã³ããèµ·åãã¾ããã¢ã¯ãã£ããã£ã§åå¿ãããããã«ã対å¿ããã URL ã MIME ã¿ã¤ãã®ã¤ã³ãã³ããã£ã«ã¿ãå®ç¾©ãããã¨ãã§ãã¾ãã詳細㯠NFC 開発者ガイドã® Tag ã®å¦çã«ã¤ãã¦ãåç
§ãã¦ä¸ããã
URL ã NdefMessage ã§éãããå ´åãæååã Uri ãªãã¸ã§ã¯ããå ã¨ããæ°ãã NdefRecord ãä½æãã createUri ã¨ãã便å©ãªã¡ã½ããã使ããã¨ãã§ãã¾ããURI ããAndroid Beam ã®ã¤ãã³ãä¸åä¿¡ããã¢ããªã±ã¼ã·ã§ã³ãç¹å¥ãªãã©ã¼ãããã§ããã¨ããå ´åãéããã¦ãã NDEF ã¡ãã»ã¼ã¸ãåä¿¡ããããã«ãåä¸ã® URI ã¹ãã¼ã ã使ç¨ããã¢ã¯ãã£ããã£ã®ããã®ã¤ã³ãã³ããã£ã«ã¿ãçæãã¹ãã§ãã
ä¾ãä»ã®ã¢ããªã±ã¼ã·ã§ã³ãåãã¤ã³ãã³ãã¢ã¯ã·ã§ã³ããã£ã«ã¿ãå¦çããã¨ãã¦ããå ¥ã£ã¦ãã NDEF ã¡ãã»ã¼ã¸ãã¢ããªã±ã¼ã·ã§ã³ãå¦çãããã¨ãä¿è¨¼ããããã«ã¯ãNdefMessage ã¨å ±ã«âAndroid ã¢ããªã±ã¼ã·ã§ã³ã¬ã³ã¼ã" ã渡ãããã«ãã¹ãã§ããcreateApplicationRecord() ãå¼ã³åºããã¨ã§ Android ã¢ããªã±ã¼ã·ã§ã³ã¬ã³ã¼ã ãçæãããã¨ãã§ããã¢ããªã±ã¼ã·ã§ã³ã®ããã±ã¼ã¸åã渡ããã¨ãã§ãã¾ããã¢ããªã±ã¼ã·ã§ã³ã¬ã³ã¼ãã¨ãç¹å®ã®ã¤ã³ãã³ããå¦çããã¢ã¯ãã£ããã£ãå«ãè¤æ°ã®ã¢ããªã±ã¼ã·ã§ã³ãä¼´ã NDEF ã¡ãã»ã¼ã¸ãä»ã®ããã¤ã¹ã§ä»ã®ããã¤ã¹ãåä¿¡ããæãã·ã¹ãã ã¯ãã¤ãï¼ã¢ããªã±ã¼ã·ã§ã³ã¬ã³ã¼ãã«ããããããã®ã«åºã¥ããï¼ã¢ããªã±ã¼ã·ã§ã³ä¸ã®ã¢ã¯ãã£ããã£ã«ã¡ãã»ã¼ã¸ãé ä¿¡ãã¾ãããã®éãã¿ã¼ã²ããã®ããã¤ã¹ã«ã¢ããªã±ã¼ã·ã§ã³ãã¤ã³ã¹ãã¼ã«ããã¦ããªãå ´åãã·ã¹ãã 㯠Android ãã¼ã±ãããèµ·åãã¦ã¦ã¼ã¶ã«ã¢ããªã±ã¼ã·ã§ã³ãã¤ã³ã¹ãã¼ã«ãããããã« Android application record ãç¨ãã¾ãã
ã¢ããªã±ã¼ã·ã§ã³ã NDEF ããã·ã¥ã¡ãã»ã¼ã¸ãè¡ãã®ã« NFC API ã使ããªãå ´åããã®æ㯠Android ã¯æ¨æºã®æ¯ãèããè¡ãã¾ãï¼ããããã¤ã¹ã®ã¢ããªã±ã¼ã·ã§ã³ããã©ã¢ã°ã©ã¦ã³ãã«ãããä»ã® Android ããã¤ã¹ãã Android Beam ãèµ·åãããæãä»ã®ããã¤ã¹ã¯ Android ã¢ããªã±ã¼ã·ã§ã³ã¬ã³ã¼ãã¨ã¢ããªã±ã¼ã·ã§ã³ã®ID ãå«ã NDEF ã¡ãã»ã¼ã¸ãåä¿¡ãã¾ããåä¿¡ããããã¤ã¹ã«ã¢ããªã±ã¼ã·ã§ã³ãæ¢ã«ã¤ã³ã¹ãã¼ã«ããã¦ããå ´åãã·ã¹ãã ã¯ãããèµ·åãã¾ããã¤ã³ã¹ãã¼ã«ããã¦ããªãå ´åã¯ãAndroid ãã¼ã±ãããéããã¤ã³ã¹ãã¼ã«ããããã«ã¦ã¼ã¶ãæ¡å ãã¾ãã
Android Beam 㨠ãã®ä»ã® NFC ã®æ©è½ã«ã¤ãã¦ãNFC 基本 éçºè ã¬ã¤ããèªããã¨ãã§ãã¾ããAndroid Beam ã使ã£ããµã³ãã«ã³ã¼ã㯠Android Beam デモã御覧ãã ããã
Android Beam ã®è©³ç´°
Android Beam ã¯ã2ã¤ã®Androidããã¤ã¹éã§ã·ã³ãã«ãªãã¢ã»ãã¼ã»ãã¢ãã¼ã¿äº¤æãå¯è½ã«ãã¾ããä»ã®ããã¤ã¹ã¸ãã¼ã¿ãéãããã¢ããªã±ã¼ã·ã§ã³ã¯ããã©ã¢ã°ã©ã¦ã³ãã«ãã¦ãä¸ã¤ããã¼ã¿ãåä¿¡ããããã¤ã¹ãããã¯ããã¦ããªããã¨ãå¿ è¦ã§ããåä¿¡å´ã®ããã¤ã¹ã«æ¥è§¦ãããããååã«éä¿¡ããããã¤ã¹ãè¿ã¥ããã¨ãéä¿¡å´ã®ãã£ã¹ãã¬ã¤ã« "Touch to Beam" UIã表示ããã¾ããã¦ã¼ã¶ã¼ã¯åä¿¡å´ã®ããã¤ã¹ã«ã¡ãã»ã¼ã¸ãåä¿¡ãããã©ãããé¸æãããã¨ãã§ãã¾ãã
注æï¼ãã©ã¢ã°ã©ã¦ã³ã NDEF ããã·ã³ã°ã¯ API ã¬ãã«10ãã使ç¨å¯è½ã§ãAndroid Beam ã¨åæ§ã®æ©è½ãæãã¾ãããããã® API 群ã¯éæ¨å¥¨ã¨ãªãã¾ããããæ§ããã¤ã¹ããµãã¼ããããã¨ãå¯è½ã§ãã詳細ã¯enableForegroundNdefPush() ãã覧ä¸ããã
ã¢ããªã±ã¼ã·ã§ã³ã§ Android Beam ãæå¹ã«ããããã«ã次ã®2ã¤ã®ã¡ã½ããã®ãã¡ããããã使ç¨ã§ãã¾ãï¼
- setNdefPushMessage()ï¼ éä¿¡ããã¡ãã»ã¼ã¸ãã»ããããããã®NdefMessage ãåãå ¥ãã¾ãã2ã¤ã®ããã¤ã¹ãååè¿ãã«é£æ¥ããã¨èªåçã«ã¡ãã»ã¼ã¸ãéä¿¡ãã¾ãã
- setNdefPushMessageCallback()ï¼éä¿¡ç¯å²å ã«ããã¤ã¹ãåå¨ããæã«å¼ã³åºãããcreateNdefMessage() ãå«ãã³ã¼ã«ããã¯ãåãå ¥ãã¾ããã³ã¼ã«ããã¯ã¯å¿ è¦ãªæã«éã£ã¦ãNDEF ã¡ãã»ã¼ã¸ãçæããã¾ãã
ã¢ã¯ãã£ããã£ã¯ãï¼åº¦ã«ï¼ã¤ã® NDEF ã¡ãã»ã¼ã¸ã®ã¿ãããã·ã¥ãããã¨ãå¯è½ã§ãããã®ããã両æ¹ãã»ããããã¦ããæã¯ãsetNdefPushMessageCallback() 㯠setNdefPushMessage() ãããåªå ããã¾ãã
Android Beam ã使ãããã«ã¯ãä¸è¨ã®ä¸è¬çãªã¬ã¤ãã©ã¤ã³ã«å¾ãå¿ è¦ãããã¾ãï¼
- ãã¼ã¿ãéä¿¡ããã¢ã¯ãã£ããã£ã¯ãã©ã¢ã°ã©ã¦ã³ãã«ããå¿ è¦ãããã¾ãã両ããã¤ã¹å ±ã«ã¹ã¯ãªã¼ã³ã¯ã¢ã³ããã¯ç¶æ ã§ããå¿ è¦ãããã¾ãã
- NdefMessage ãªãã¸ã§ã¯ãã«éä¿¡ããããã¼ã¿ãã«ãã»ã«åããå¿ è¦ãããã¾ãã
- éä¿¡ããããã¼ã¿ãåä¿¡ããNFC ããã¤ã¹ã¯ãcom.android.npp NDEF push protocol ããNFC ãã©ã¼ã©ã ã® SNEP(Simple NDEF Exchange Protocol) ã®ããããããµãã¼ãããå¿ è¦ãããã¾ããcom.android.npp ãããã³ã«ã¯ API ã¬ãã«9 (Android 2.3) ãã API ã¬ãã«13 (Android 3.2) ã®ããã¤ã¹ãå¿ è¦ã§ããcom.android.npp 㨠SNEP ã®ä¸¡æ¹ã¯ API ã¬ãã«14 (Android 4.0) 以éãå¿ è¦ã§ãã
注æï¼Android Beam ã使ç¨å¯è½ãªã¢ã¯ãã£ããã£ããã©ã¢ã°ã©ã¦ã³ãã«ããå ´åãæ¨æºçãªã¤ã³ãã³ãã®å¦çã¯ç¡å¹ã¨ãªãã¾ããããããã¢ã¯ãã£ããã£ãフォアグラウンドで処理するãã¨ãã¾ãæå¹ã§ããå ´åããã©ã¢ã°ã©ã¦ã³ãå¦çä¸ã«ã¤ã³ãã³ããã£ã«ã¿ã«ãããããã¿ã°ãå¼ãç¶ãã¹ãã£ã³ããäºãã§ãã¾ãã
Android Beam ãæå¹ã«ããããã«ï¼
- ä»ã®ããã¤ã¹ã¸ããã·ã¥ããã NdefRecords ãå«ãã NdefMessage ãçæãã¾ãã
- NdefMessage ãå«ã setNdefPushMessage() ãå¼ã³åºãããã¢ã¯ãã£ããã£ä¸ã® onCreate() ã¡ã½ããã®ä¸ã§ NfcAdapter.CreateNdefMessageCallback ãªãã¸ã§ã¯ãã渡ããã setNdefPushMessageCallback ãå¼ã³åºãã¾ãããããã®ã¡ã½ããã¯ãæ´»æ§åãããä»ã®ã¢ã¯ãã£ããã£ã®ãªãã·ã§ã³ã®ãªã¹ãã¨å ±ã«ã Android Beam ã§æå¹ã«ãããã¢ã¯ãã£ããã£ãå°ãªãã¨ã1ã¤ã¯å¿ è¦ã§ãã
ä¸è¬ã«ã2ã¤ã®ããã¤ã¹ãã³ãã¥ãã±ã¼ã·ã§ã³ããç¯å²å ã«ããå ´åãã¢ã¯ãã£ããã£ããã¤ãåã NDEF ã¡ãã»ã¼ã¸ãããã·ã¥ããå¿ è¦ãããã ãã§ããå ´åã¯ãé常 setNdefPushMessage() ã使ãã¾ããã¢ããªã±ã¼ã·ã§ã³ãç¾å¨ã®ã¢ããªã±ã¼ã·ã§ã³ã®ã³ã³ããã¹ããæ±ãããæãã¦ã¼ã¶ãã¢ããªã±ã¼ã·ã§ã³ã«å¯¾ãã¦è¡ã£ã¦ãããã¨ã«ä¾åãã NDEF ã¡ãã»ã¼ã¸ãããã·ã¥ãããæã¯ãsetNdefPushMessageCallback ã使ãã¾ãã
以ä¸ã¯ ã¢ã¯ãã£ããã£ã® onCreate() ã¡ã½ããä¸ã§ãNfcAdapter.CreateNdefMessageCallback ãå¼ã³åºãåç´ãªã¢ã¯ãã£ããã£ãã©ã®ããã«å®è£ ãããã®ä¾ã§ãï¼å®å ¨ãªãµã³ãã«ã御覧ãã ããï¼ããã®ä¾ã¯ã¾ã MIME ã¬ã³ã¼ãã®ä½ãæ¹ã示ãã¦ãã¾ãï¼
package com.example.android.beam; import android.app.Activity; import android.content.Intent; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.nfc.NfcAdapter; import android.nfc.NfcAdapter.CreateNdefMessageCallback; import android.nfc.NfcEvent; import android.os.Bundle; import android.os.Parcelable; import android.widget.TextView; import android.widget.Toast; import java.nio.charset.Charset; public class Beam extends Activity implements CreateNdefMessageCallback { NfcAdapter mNfcAdapter; TextView textView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView textView = (TextView) findViewById(R.id.textView); // å©ç¨å¯è½ãªNFC ã¢ããã¿ã®ãã§ã㯠mNfcAdapter = NfcAdapter.getDefaultAdapter(this); if (mNfcAdapter == null) { Toast.makeText(this, "NFC is not available", Toast.LENGTH_LONG).show(); finish(); return; } // ã³ã¼ã«ããã¯ãç»é²ãã mNfcAdapter.setNdefPushMessageCallback(this, this); } @Override public NdefMessage createNdefMessage(NfcEvent event) { String text = ("Beam me up, Android!\n\n" + "Beam Time: " + System.currentTimeMillis()); NdefMessage msg = new NdefMessage( new NdefRecord[] { createMimeRecord( "application/com.example.android.beam", text.getBytes()) /** * Android Application Record(AAR)ã¯ã³ã¡ã³ãã¢ã¦ãããã¦ãã¾ãã * ããã¤ã¹ãAARãå«ãããã·ã¥ãåä¿¡ããæãã¢ããªã±ã¼ã·ã§ã³ã¯ * å®è¡ãä¿è¨¼ããããã«AARãæå®ãã¾ããAARã¯ã¿ã°ã®å¦çã·ã¹ãã ããªã¼ãã¼ã©ã¤ããã¾ãã * ã¡ãã»ã¼ã¸ãåä¿¡ããæã«ãã®ã¢ã¯ãã£ããã£ãéå§ããããã¨ãä¿è¨¼ããããã«ã * å¾ãã«è¿½å ãããã¨ãã§ãã¾ããä»ã®ã¨ããããã®ã³ã¼ãã¯ã¿ã°å¦ç * ã·ã¹ãã ã使ã£ã¦ãã¾ãã */ //,NdefRecord.createApplicationRecord("com.example.android.beam") }); return msg; } @Override public void onResume() { super.onResume(); // ã¢ã¯ãã£ããã£ãAndroid Beamã«ãã£ã¦éå§ããããã¨ããã§ãã¯ãã if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { processIntent(getIntent()); } } @Override public void onNewIntent(Intent intent) { // ã¤ã³ãã³ããå¦çããããã«ããã®å¾ã§onResumeãå¼ã°ãã setIntent(intent); } /** * ã¤ã³ãã³ãããã®NDEFã¡ãã»ã¼ã¸ã®ãã¼ã¹ã¨TextViewã¸ã®è¡¨ç¤º */ void processIntent(Intent intent) { textView = (TextView) findViewById(R.id.textView); Parcelable[] rawMsgs = intent.getParcelableArrayExtra( NfcAdapter.EXTRA_NDEF_MESSAGES); // ãã¼ã ã®éä¿¡ä¸ã¯ä¸ã¤ã ãã®ã¡ãã»ã¼ã¸ NdefMessage msg = (NdefMessage) rawMsgs[0]; // ç¾å¨ã¯ãã¬ã³ã¼ã0ã¯MIMEã¿ã¤ããå«ããã¬ã³ã¼ã1ã¯AARãå«ã textView.setText(new String(msg.getRecords()[0].getPayload())); } /** * NDEFã¬ã³ã¼ãå ã«ã«ã¹ã¿ã MIMEã¿ã¤ããã«ãã»ã«åãã¦çæãã */ public NdefRecord createMimeRecord(String mimeType, byte[] payload) { byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII")); NdefRecord mimeRecord = new NdefRecord( NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload); return mimeRecord; } }
ãã®ã³ã¼ãã¯AARãã³ã¡ã³ãã¢ã¦ããã¦ãã¾ãããé¤å»ã§ãããã¨ã«æ³¨æãã¦ä¸ãããAARãæå¹ã«ããå ´åãAARä¸ã®ç¹å®ã®ã¢ããªã±ã¼ã·ã§ã³ã¯å¸¸ã«Android Beam ã¡ãã»ã¼ã¸ãåä¿¡ãã¾ããã¢ããªã±ã¼ã·ã§ã³ãåå¨ããªãå ´åãAndroid Market ãã¢ããªã±ã¼ã·ã§ã³ããã¦ã³ãã¼ãããããã«èµ·åãã¾ãããããã£ã¦ãAAR ã使ãããå ´åãä¸è¨ã®ã¤ã³ãã³ããã£ã«ã¿ã¯ Android 4.0 以éã®ããã¤ã¹ã§ã¯æè¡çã«å¿ è¦ããã¾ããï¼
<intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="application/com.example.android.beam"/> </intent-filter>
ãã®ã¤ã³ãã³ããã£ã«ã¿ã«ããã com.example.android.beam ã¢ããªã±ã¼ã·ã§ã³ã NFC ã¿ã°ãã¹ãã£ã³ããæãcom.example.android.beam åã®AARãä¼´ãAndroid Beamãåä¿¡ããæãã¾ãã¯ãNDEF ãã©ã¼ãããã®ã¡ãã»ã¼ã¸ã application/com.example.android.beam åã® MIME ã¬ã³ã¼ããå«ãã§ããæã«ãéå§ãããã¨ãã§ãã¾ãã
ä¾ã AAR ãã¢ããªã±ã¼ã·ã§ã³ã®éå§ã¨ãã¦ã³ãã¼ããä¿è¨¼ãã¦ãã¦ããã¤ã³ãã³ããã£ã«ã¿ã¯æ¨å¥¨ããã¾ããä½æ ãªããAAR ã«ãã£ã¦ç¹å®ãããããã±ã¼ã¸ã®ç¯å²å ã«ããã¡ã¤ã³ã®ã¢ã¯ãã£ããã£ã常ã«éå§ãã代ããã«ãã¢ããªã±ã¼ã·ã§ã³ä¸ã®éå§ããã¢ã¯ãã£ããã£ãé¸æããä½å°ãä¸ããããã§ããAAR ã¯ã¢ã¯ãã£ããã£ã¬ãã«ã®ä¿è¨¼ã¯è¡ãã¾ãããã¾ããããã¤ãã® Android 端æ«ã¯ AAR ããµãã¼ãããªããããä¸ãä¸ã®ããã«ãNDEF ã¡ãã»ã¼ã¸ã®æåã® NDEF ã¬ã³ã¼ãã«ãIDã®æ å ±ãåãè¾¼ã¿ãåæ§ã«ãã£ã«ã¿ã¼ãã¹ãã§ããã¬ã³ã¼ãã®çææ¹æ³ã«é¢ãã詳ããæ å ±ã¯ãNDEF レコードの共通タイプの作成ã御覧ãã ããã
æ責ï¼æè¡é¨ãç¬æ¸ ç´åãTweet