在 Samsung Galaxy 设备上隐藏 "NFC Tag type not supported" 错误

Hide "NFC Tag type not supported" error on Samsung Galaxy devices

我正在开发一款仅扫描 MIFARE Classic 卡的 UID 以方便考勤登记的应用程序。我让它工作了。然而,每次我在我的 Galaxy S4 上扫描一张卡片时,我都会得到一个提示 "NFC tag type not supported"。

我想在应用程序打开时阻止或隐藏该消息。

我注意到 one other question 在 Galaxy S6 上提出了同样的要求,但它被否决了一次,然后被忽略了。

我在三星开发者论坛上找到了 this 对话,但是,我无法从那里写的内容中提取答案:

  if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) {
      myTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); 
      tagID = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
      alertDialog.dismiss(); 

看起来 alertDialog.dismiss() 部分是我需要的,但没有解释他们从哪里得到 alertDialog 对象。

之前 Android 4.4

您尝试做的事情根本不可能通过应用程序实现(至少在 non-rooted/non-modified 设备上是不可能的)。消息 "NFC tag type not supported" 由 Android 系统(或更具体地说是 NFC 系统服务)在将标签分派到您的应用程序之前显示,而不是。这意味着 NFC 系统服务会过滤 MIFARE Classic 标签,并且永远不会将它们通知给任何应用程序。因此,您的应用无法检测到 MIFARE Classic 标签或绕过该弹出消息。

在获得 root 权限的设备上,您可以使用

  1. Xposed 修改 NFC 服务的行为,或者
  2. 系统分区上的 CSC(消费者软件定制)功能配置文件(参见 /system/csc/。如果 CSC功能 <CscFeature_NFC_EnableSecurityPromptPopup> 设置为除 "mifareclassic" 或 "all" 之外的任何值。例如,您可以使用:

    <CscFeature_NFC_EnableSecurityPromptPopup>NONE</CscFeature_NFC_EnableSecurityPromptPopup>
    

    例如,您可以将此条目添加到文件“/system/csc/others.xml”(在该文件中已存在的 <FeatureSet> ... </FeatureSet> 部分)。

因为你也要求 Galaxy S6(question that you linked):我已经在 S4 上测试了这个方法。我还没有验证这是否仍然适用于最新的固件或其他设备(例如 S6)。

因为 Android 4.4

这纯属猜测,但是according to this (link no longer available), it seems that some apps (e.g. NXP TagInfo) are capable of detecting MIFARE Classic tags on affected Samsung devices since Android 4.4. This might mean that foreground apps are capable of bypassing that popup using the reader-mode API (see NfcAdapter.enableReaderMode) possibly in combination with NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK