androidNFC标签活动在NFC标签不再被检测到后仍然存在的问题
创始人
2024-10-09 11:01:44
0

您可以使用onNewIntent方法来处理NFC标签被移除的情况。以下是一个示例,它在NFC标签被检测到时会显示一个活动,并在NFC标签被移除时关闭该活动:

public class MainActivity extends AppCompatActivity {
    private NfcAdapter nfcAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            handleNfcIntent(getIntent());
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handleNfcIntent(intent);
    }

    private void handleNfcIntent(Intent intent) {
        // This is where you handle the NFC tag's data
        // For example, you can display the tag's data in a TextView

        // Close this activity when the NFC tag is removed
        if (intent.getAction().equals(NfcAdapter.ACTION_TAG_LOST)) {
            finish();
        }
    }
}

相关内容

热门资讯

透视透视!HH平台挂,aapo... 透视透视!HH平台挂,aapoker透视脚本,指南教程(确实存在有挂)-哔哩哔哩1)aapoker透...
透视安卓版本!wepoker俱... 透视安卓版本!wepoker俱乐部辅助(透视)开挂辅助插件(确实真的有挂)-哔哩哔哩1.wepoke...
透视规律!德普辅助器怎么用,w... 透视规律!德普辅助器怎么用,wepokerplus到底是挂了吗,总结教程(一直存在有挂)-哔哩哔哩1...
透视黑科技!wepoker破解... 透视黑科技!wepoker破解器,有没有人wepoker,指引教程(原来真的是有挂)-哔哩哔哩1、有...
透视规律!wepoker怎么买... 透视规律!wepoker怎么买辅助(透视)开挂辅助插件(真是真的是有挂)-哔哩哔哩运wepoker怎...
透视规律!wepoker辅助器... 透视规律!wepoker辅助器免费,we poker辅助器下载,指引教程(都是有挂)-哔哩哔哩暗藏猫...
透视开发!aa poker透视... 透视开发!aa poker透视软件(透视)开挂辅助攻略(竟然存在有挂)-哔哩哔哩所有人都在同一条线上...
透视神器!wepokerh5破... 透视神器!wepokerh5破解,wepoker怎么下载游戏,窍要教程(总是是真的挂)-哔哩哔哩1、...
透视识别!wepoker-h5... 透视识别!wepoker-h5下载(透视)开挂辅助挂(果然是有挂)-哔哩哔哩1、许多玩家不知道wep...
透视总结!wepoker有透视... 透视总结!wepoker有透视功能吗,大菠萝手游辅助,方式教程(一直是真的挂)-哔哩哔哩1、完成we...