Code example for NfcAdapter

Methods: enableForegroundDispatch

0
    private void enableTagWriteMode() { 
        IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
        mWriteTagFilters = new IntentFilter[] {
            tagDetected
        }; 
        mNfcAdapter.enableForegroundDispatch(this, getPendingIntent(), mWriteTagFilters, null);
    } 
 
    @Override 
    protected void onNewIntent(Intent intent) {
        // Tag writing mode 
        if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
            Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
            if (NFCProfileUtils.writeTag(NFCProfileUtils.getProfileAsNdef(mProfile), detectedTag)) {
                Toast.makeText(this, R.string.profile_write_success, Toast.LENGTH_LONG).show();
                NFCProfileUtils.vibrate(this);
            } else { 
                Toast.makeText(this, R.string.profile_write_failed, Toast.LENGTH_LONG).show();
            } 
            finish();
Contextual code suggestions in your IDE  Get Codota for Java