【问题标题】:How to get URL of Smart Poster in app launched by AAR如何在 AAR 推出的应用中获取智能海报的 URL
【发布时间】:2013-08-14 10:26:34
【问题描述】:

我有一张 NFC 卡,上面写有 Smart Poster 和 AAR

NdefMessage message = new NdefMessage(smartPosterRecord, aarRecord);

当我将此卡附加到设备时,我在 AAR 中定义的演示应用程序启动,但 intent.getAction() 返回 android.intent.action.MAIN 而不是 NfcAdapter.ACTION_TAG_DISCOVEREDNfcAdapter.ACTION_TECH_DISCOVERED,因此我无法从中获取标签。

应该怎么做才能读取智能海报的URL?

Ndef:

NdefRecord uriRecord = NdefRecord.createUri(uri);
NdefMessage message = new NdefMessage(uriRecord);

NdefRecord smartPosterRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_SMART_POSTER, new byte[0], message.toByteArray());
NdefRecord aarRecord = NdefRecord.createApplicationRecord(aar);

message = new NdefMessage(smartPosterRecord, aarRecord);

// Get instance of Ndef for the given tag
Ndef ndef = Ndef.get(tag);
// Enable I/O
ndef.connect();

// Write the message
ndef.writeNdefMessage(message);

// Close the connection
ndef.close();

意图处理:

public void handleIntent(Intent intent) {
    if (((NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction()))) || (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction()))) {
        // do something
    }

清单:

    <activity
        android:name="com.demo.app.DemoActivity"
        android:label="GeneralDemo"
        android:launchMode="singleInstance" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.TECH_DISCOVERED" />
        </intent-filter>
         <intent-filter>
            <action android:name="android.nfc.action.TAG_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.nfc.action.TECH_DISCOVERED"
            android:resource="@xml/nfcfilter" />

    </activity>

【问题讨论】:

    标签: android android-intent nfc ndef android-applicationrecord


    【解决方案1】:

    将其添加到清单中就可以了:

            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <category android:name="android.intent.category.DEFAULT"/>
                 <data android:scheme="http"
                    android:host="demo.com" /> 
            </intent-filter>
    

    应用程序不是因为 AAR 而启动,而是因为“捕获”了智能海报的 url...

    编辑: 最后,我们决定使用我们在应用中捕获的自定义 MimeType(通过意图过滤器)

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 1970-01-01
      • 2021-11-15
      • 2013-02-12
      • 1970-01-01
      • 2019-03-22
      • 2012-06-18
      • 1970-01-01
      • 2014-06-06
      相关资源
      最近更新 更多