安卓如何自动执行检测到的NFC标签,无需再点确认

我用的软件是:macrodroid
手机是红米k50
很怪,每次执行都要点击“打开”

img

望采纳,谢谢!
1、可以使用Android的Foreground Dispatch系统来自动执行检测到的NFC标签,无需再点确认。Foreground Dispatch系统允许应用程序注册一个intent-filter,以便在检测到NFC标签时自动启动应用程序。应用程序可以使用PendingIntent类来定义要在检测到NFC标签时执行的操作。
2、要自动执行检测到的NFC标签,需要在应用中实现NFC标签的自动处理功能。

  1. 首先,需要在应用的AndroidManifest.xml文件中添加如下权限:
<uses-permission android:name="android.permission.NFC" />
  1. 然后,在应用中实现NFC标签的处理程序,例如:
public class MyNfcHandler extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        nfcAdapter.enableForegroundDispatch(this, new Intent(this, MyNfcHandler.class), null, null);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        // 在这里处理NFC标签
    }
}
  1. 最后,在应用的AndroidManifest.xml文件中添加如下intent-filter:
<activity android:name=".MyNfcHandler">
    <intent-filter>
        <action android:name="android.nfc.action.TAG_DISCOVERED" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

以上就是实现自动执行检测到的NFC标签的步骤,无需再点击确认按钮。

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^