跨平台的推出与记录在Windows Phone和Android的额外数据 [英] Cross platform launch records with extra data on Windows Phone and Android

查看:219
本文介绍了跨平台的推出与记录在Windows Phone和Android的额外数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能建立一个跨平台的NDEF消息开始在Android上的和应用的Windows Phone传递更多数据的应用程序?

Is it possible to create a cross platform NDEF Message to start an application on Android and Windows Phone passing additional data to the app?

我所试图做的事:

我已经安装在Android和Windows Phone的应用程序。应该可以开始与NFC标签的应用程序,我需要从标签(任意字符串),以我的应用程序传递额外的数据。

I have an application installed on Android and Windows Phone. It should be possible to start the applications with an NFC tag and I need to pass additional data from the tag (any string) to my applications.

要开始使用NFC标签的应用程序,我创建了一个Windows Phone的LaunchApp记录和Android应用程序记录(AAR),并将其存储在标签上。

To start the applications with the NFC tags, I created a Windows Phone LaunchApp Record and an Android Application Record (AAR) and store them on the tag.

Windows Phone的需要LaunchApp记录是第一个NDEF记录在NDEF消息。所以NDEF消息的顺序是:

Windows Phone needs the LaunchApp Record to be the first NDEF Record in the NDEF message. So the sequence of the NDEF message is:


  1. Windows Phone的LaunchApp记录

  2. Android应用程序记录

要通过额外的数据,我可以把一些参数在Windows Phone LaunchApp记录,使工作正常。但它不是可能把一些额外的数据传输到Android应用程序记录。

To pass additional data, I can put some arguments in the Windows Phone LaunchApp Record, so that works fine. But it is not possible to put some additional data to the Android Application Record.

我想第三NDEF记录添加到包含Android的额外数据的消息。我创建了一个外部的记录,我加了过滤器,我的清单。

I tried to add a third NDEF Record to the message which contains the extra data for Android. I created an external record and I added the filter to my manifest.

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="vnd.android.nfc"
        android:host="ext"
        android:pathPrefix="/myapp.com:customtype"/>
</intent-filter>

的问题是在NDEF消息的序列:

The problem is the sequence of the the NDEF message:

在Windows Phone记录必须是消息中的第一条记录,但附加记录也必须接受在Android上的意图的第一条记录。

The Windows Phone record must be the first record in the message, but the additional record must also be the first record to receive the intent on Android.

NDEF消息:


  1. 外部和LaunchApp记录

  2. Android应用程序记录

如果我有以下记录序列我收到Android和额外数据的应用程序启动,但随后因为该记录是第二个我无法打开在Wi​​ndows Phone应用程序。

If I have following record sequence I receive the extra data on Android and the application starts but then I can't open the application on Windows Phone because the record is the second one.


  1. 外部记录

  2. Windows Phone的LaunchApp

  3. Android应用程序记录

有没有办法解决这个问题?我缺少的东西吗?

Is there any solution to this problem? Am I missing something?

推荐答案

这里的问题是:


  • Windows需要的LaunchApp纪录是标签上的NDEF消息的第一条记录。

  • Android将只发现NDEF消息/ NFC标签对象传递给应用程序如果应用的NDEF消息的第一条记录的意图过滤器。

  • 的LaunchApp记录不是一个有效的NDEF记录(其类型名称格式表示绝对URI记录,但它的类型(windows.com/LaunchApp)是的不可以有效的绝对URI)。

  • Windows requires the LaunchApp record to be the first record of the NDEF message on the tag.
  • Android will only pass the discovered NDEF message/NFC tag object to the app if the app has an intent filter for the first record of the NDEF message.
  • The LaunchApp record is not a valid NDEF record (as its type name format indicates an absolute URI record but its type ("windows.com/LaunchApp") is not a valid absolute URI).

因此​​,你不能轻易的记录(LaunchApp记录)与在令计划在Android(URI意图过滤器匹配的意图过滤器匹配 - >主机 - >路径,但由于没有计划,你可以不匹配主机/路径)。

As a consequence, you cannot easily match that record (the LaunchApp record) with an intent filter on Android (URI intent filters match in the order scheme -> host -> path, but as there is no scheme, you cannot match for host/path).

诀窍是使用任何URI与空计划相匹配的意图过滤器:

The trick is to use an intent filter that matches any URI with an empty scheme:

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

现在,如果你的NDEF消息

Now if your NDEF message is

LaunchApp record | [optional other records] | Android Application record

您的Andr​​oid应用程序将被调用和NDEF消息/标记对象将在 NDEF_DISCOVERED 的意图传递给上述意图过滤器的活动。

your Android app will be invoked and the NDEF message/tag object will be passed in an NDEF_DISCOVERED intent to the activity with the above intent filter.

不幸的是,意图过滤器也将被触发,它包含一个相对URI /任何URI没有计划任何其他标​​记,并且不包含AAR的另一个应用程序。

Unfortunately, that intent filter will also be triggered for any other tag that contains a relative URI/any URI without a scheme and that does not contain an AAR for another app.

更新

code创建我的测试LaunchApp记录标记:

Code for creating my test LaunchApp record tag:

final Ndef ndefTag = Ndef.get(tag);

if (ndefTag != null) {
    try {
        ndefTag.connect();
        ndefTag.writeNdefMessage(new NdefMessage(new NdefRecord[] {
                    new NdefRecord(NdefRecord.TNF_ABSOLUTE_URI,
                                   "windows.com/LaunchApp".getBytes("US-ASCII"),
                                   null,
                                   "la:uz".getBytes("US-ASCII")),
                    NdefRecord.createApplicationRecord("at.mroland.launchrecordtest")
        }));
    } catch (Exception e) {
    } finally {
        try {
            ndefTag.close();
        } catch (Exception ee) {
        }
    }
}

舱单接收应用程序:

Manifest for the receiving app:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="at.mroland.launchrecordtest"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.NFC" />
    <uses-feature android:name="android.hardware.nfc" android:required="true" />
    <application android:label="@string/app_name"
                 android:icon="@drawable/ic_launcher">
        <activity android:name=".LaunchRecordTest"
                  android:label="LaunchRecordTest">
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="" />
            </intent-filter>
        </activity>
    </application>
</manifest>

的onCreate(),我用 getIntent()来检索的意图。

In onCreate(), I used getIntent() to retrieve the intent.

这篇关于跨平台的推出与记录在Windows Phone和Android的额外数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆