LoginSignup
1
4

More than 5 years have passed since last update.

[nrf52]NFCでURIの代わりにAndroidアプリを立ち上げる

Posted at

nRF52のNFC URIサンプルをちょっと変更して、Androidアプリを起動させるようにしてみる。

アプリがインストールされていれば起動するし、なければGoogle Playの該当サイトに飛ぶ(勝手にインストールはされない)。

#if 0したところが既存で、#else側が書き換えたソースだ。
自分のアプリにするのは何かいやらしいので、Nordicの"nRF Master Control Panel"にした。

#if 0
    /* Create NFC message */
    nfc_uri_id_t id_www = NFC_URI_HTTP_WWW;         /* Choose protocol for the URL */

    err_code = nfc_uri_msg_create(id_www,
                                  (uint8_t *) url,
                                  sizeof(url),
                                  &p_nfc_msg,
                                  &nfc_msg_len);
    APP_ERROR_CHECK(err_code);
#else
    /* AAR */
    uint8_t ndef[256];
    uint8_t *p = ndef;
    const char PACKAGE_NAME[] = "no.nordicsemi.android.mcp";
    const char EXTERNAL_TYPE[] = "android.com:pkg";

    *p++ = 0xd4;     //MB=ME=1, TNF=External
    *p++ = 15;       //"android.com:pkg"
    *p++ = (uint8_t)(sizeof(PACKAGE_NAME) - 1);
    memcpy(p, EXTERNAL_TYPE, sizeof(EXTERNAL_TYPE) - 1);
    p += sizeof(EXTERNAL_TYPE) - 1;
    memcpy(p, PACKAGE_NAME, sizeof(PACKAGE_NAME) - 1);
    p += sizeof(PACKAGE_NAME) - 1;
    nfc_msg_len = (uint16_t)(p - ndef);
    p_nfc_msg = ndef;
#endif
1
4
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
1
4