禁止梁触摸模式 [英] Disable beam touch mode

查看:284
本文介绍了禁止梁触摸模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中一个特殊的活动A能够传送数据:

I have an app where a special Activity A is able to transfer data:

当设备1是活性和你设备2配对(无论身在何处设备2,即使该应用程序不启动)数据成功束触摸后transfferred。活动A的意图过滤器:

When Device1 is in Activity A and you pair it with Device2 (no matter where Device2 is, even if the app is not started) the data is successfully transfferred after the beam touch. Activity A has the intent filter:

       <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/de.my.app" />
        </intent-filter>

在做了必要的推动。

on does the necessary push.

但是,当我在另一个活动B,这也使得

But when I am in another activity B, this also makes


  1. 另一台设备启动应用程序

  2. 请如果应用程序已启动两个设备上的触控模式出现。我不希望任何设备有变化,现在要做的光束。如果你是Android的桌面上,并在配对设备,你没有得到的光束过于对话框。你只是得到一个小的震动。这就是我想在这里。这可能吗?

在此先感谢!

推荐答案

在活动B,您可以打开前景,调度,忽略任何NFC的意图和禁止发送Android Beam的消息:

In Activity B, you can turn on foreground-dispatching, ignore any NFC intents and disable sending Android Beam messages:

private NfcAdapter nfcAdapter;

protected void onCreate(Bundle savedInstanceState) {
  ...
  nfcAdapter = NfcAdapter.getDefaultAdapter(this);
  // turn off sending Android Beam
  nfcAdapter.setNdefPushMessage(null, this);
}

protected void onResume() {
  // catch all NFC intents
  Intent intent = new Intent(getApplicationContext(), getClass());
  intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
  nfcAdapter.enableForegroundDispatch(this, pintent, null, null);
}

protected void onPause() {
  nfcAdapter.disableForegroundDispatch(this);
}

protected void onNewIntent(Intent intent) {
  if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction()) {
    return; // ignore NFC intents
  }
}

您可以让这个更具体一点只为 NDEF 技术过滤的PendingIntent 和/或在检查 onNewIntent()其他什么技术标签对象支持。 Android Beam的意图总是有 NDEF 技术并没有其他人。

You could make this a little more specific by filtering only for the Ndef technology in the PendingIntent and/or checking in the onNewIntent() what other technologies the Tag object supports. Android Beam intents always have the Ndef technology and no other ones.

这篇关于禁止梁触摸模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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