小号梁的优先级高于我的NFC应用 [英] S Beam takes priority over my NFC app

查看:278
本文介绍了小号梁的优先级高于我的NFC应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有两个三星galaxy S4。我开发了将光束简单的文本到手机接触(目标手机)当按钮是运行应用程序(来源电话)的电话触及基于NFC的Andr​​oid应用程序。我的问题是,当我跑我的源手机上的应用程序,并把目标手机接近源手机,三星的默认应用程序启动(这个应用程序显示在源手机的当前活动的屏幕截图,并要求您触摸屏幕,然后启动在目标手机相同的活动)。
我想禁用此功能,使应用程序开发我没有任何问题的作品。
我如何做到这一点?

Hi I have two Samsung galaxy S4. I developed an NFC based android app that will beam simple text to the phone in contact (target phone) when a button is touched on the phone that runs the app(source phone). My problem is that when I run my app on the source phone and bring the target phone closer to the source phone, samsung's default app launches(This app shows a screenshot of the current activity in the source phone and asks you to touch the screen and then it launches the same activity in the target phone). I want to disable this, so that the app I developed works without any issues. How do I achieve this?

推荐答案

如果你想(或带有 1 )使用Android Beam功能,有没有办法避免梁的UI(这是与您的活动的小屏幕截图活动)。

If you want to (or have to1) use Android Beam, there is no way to avoid the Beam UI (that's the activity with the small screenshot of your activity).

为了正确地使用束(与梁UI)和发送文本 2 是要做到以下几点:

In order to properly use Beam (with the Beam UI) and send your text2 is to do the following:


  1. 启用前景调度系统,为您的目标设备上的活动,以便接收的NDEF消息立即被您的应用程序进行处理。然后,您可以接收NDEF消息(或者更确切地说,NFC发现事件在活动的 onNewIntent()方法见的如何启用前景派遣这个答案

  2. 禁用使用这样的事情(例如在接收活动的的onCreate()法)为喜气洋洋的目标设备上的活动:

  1. Enable the foreground dispatch system for the activity on your target device, so that the received NDEF message is immediately processed by your app. You can then receive NDEF messages (or rather NFC discovery events in your activity's onNewIntent() method. See this answer on how to enable the foreground dispatch.
  2. Disable beaming for the activity on your target device using something like this (e.g. in the receiving activity's onCreate() method):

NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter != null) {
    nfcAdapter.setNdefPushMessage(null, this);
}


  • 更改您的源设备发送到您实际要发送的NDEF消息(例如包含您的文字记录的NDEF消息)的NDEF消息。如果你不这样做,Android将(默认)发送一个Android应用程序记录,得到您的默认的活动要在目标设备上启动。您可以设置这样的NDEF消息(例如,在发送活动的的onCreate()法):

    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter != null) {
        byte[] text = "Hello World!".getBytes("UTF-8");
        byte[] recordPayload = new byte[3 + text.length];
        recordPayload[0] = (byte)0x02; //UTF-8, 2-byte language code
        recordPayload[1] = (byte)0x65; //'e'
        recordPayload[2] = (byte)0x6E; //'n'
        System.arraycopy(text, 0, recordPayload, 3, text.length);
        NdefMessage ndefMsg = new NdefMessage(
            new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, null, recordPayload)
        );
        nfcAdapter.setNdefPushMessage(ndefMsg, this);
    }
    


  • 如果两个设备使用Android 4.4或以上版本,而不是使用光束,你可以使用的一台设备和基于主机的卡仿真(HCE)<一个href=\"http://developer.android.com/reference/android/nfc/NfcAdapter.html#enableReaderMode%28android.app.Activity,%20android.nfc.NfcAdapter.ReaderCallback,%20int,%20android.os.Bundle%29\"相对=nofollow>在其他设备上NFC读写模式。当组合这些功能(即,有一个设备上的HCE主机上卡仿真业务,并把所述第二装置到读取模式),这两个设备可以彼此用ISO 7816-4的APDU通信。这样做的好处是,你可以完全跳过烦人的梁UI。

    If both devices use Android 4.4+, instead of using Beam, you could use Host-based Card Emulation (HCE) on one device and NFC reader mode on the other device. When you combine those features (i.e. you have a HCE on-host card emulation service on one device and put the second device into reader mode), both devices can communicate with each other using ISO 7816-4 APDUs. The advantage of this would be that you can completely skip the annoying Beam UI.

    结果

    1)那是,如果你使用的是Android版本和LT的情况; 4.4。结果
    2)我承担NDEF文字实录吧?搜索

    这篇关于小号梁的优先级高于我的NFC应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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