Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8041359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:11:21+00:00 2026-06-05T04:11:21+00:00

My activity is implementing CreateNdefMessageCallback, OnNdefPushCompleteCallback I’m calling mNfcAdapter.setNdefPushMessageCallback(this, this); // Register callback to

  • 0

My activity is implementing

CreateNdefMessageCallback, OnNdefPushCompleteCallback

I’m calling

    mNfcAdapter.setNdefPushMessageCallback(this, this);
    // Register callback to listen for message-sent success
    mNfcAdapter.setOnNdefPushCompleteCallback(this, this);

I’ve overriden

@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    Log.d(TAG, "Creating massage");
    String text = TAG + DATA_SPLITTER + ADDRESS + DATA_SPLITTER
            + USER_NAME;

    // Nachricht vorbereiten.
    // String text = "Hello NFC World!";
    NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
            MIME_TYPE.getBytes(), new byte[0], text.getBytes());
    NdefRecord[] records = { record };
    NdefMessage msg = new NdefMessage(records);
    return msg;
}

But when I’m receiving, I get different records, two of them, one with the market uri to search for the application, one with just the java package name (I guess).
Before this, I’ve simply used enableForegroundNdefPush… etc, so without any Callback, but as I need it to handle the completion of my push on both devices.. I’ve changed it to this way, and now it does not properly transfer my data anymore.

EDIT:

To make it better understandable:

public class NfcActivity extends Activity implements CreateNdefMessageCallback,
    OnNdefPushCompleteCallback {
// ================================ Member =================================
// Speichert den NFC Adapter.
private NfcAdapter mNfcAdapter = null;
private boolean retryChannel = false;

public static final String TAG = "NfcActivity";
private static final String DATA_SPLITTER = "__:DATA:__";
private static final String MIME_TYPE = "application/my.applications.mimetype";

private String ADDRESS = null;
private String USER_NAME = null;

// Speichert das Intent, welches von Android mit erkannten Tags gefüllt
// und an die Activity weitergeleitet wird.
private PendingIntent mNfcPendingIntent = null;

private static final String LOG_TAG = "NfcActivity";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ADDRESS = "Something";

    USER_NAME = "Someone";

    // Zugriff auf den NFC Adapter erhalten.
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    mNfcAdapter.setNdefPushMessageCallback(this, this);
    mNfcAdapter.setOnNdefPushCompleteCallback(this, this);

    Intent intent = new Intent(this, getClass());
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mNfcPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
}

@Override
protected void onNewIntent(Intent intent) {
    if (!NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        return;
    }

    // Nutzdaten des Intent auslesen.
    Parcelable[] rawMsgs = intent
            .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    if (rawMsgs == null) {
        return;
    }

    for (int i = 0; i < rawMsgs.length; ++i) {
        NdefMessage msg = (NdefMessage) rawMsgs[i];
        NdefRecord[] records = msg.getRecords();
        for (NdefRecord record : records) {
            String text = new String(record.getPayload());
                            // this one has the wrong content. I receive two records, one for the market, one with java packet name (or something)
        }
    }
}

@Override
protected void onResume() {
    super.onResume();

            // activate receiving of messages
    mNfcAdapter.enableForegroundDispatch(this, mNfcPendingIntent, null,
            null);
}

@Override
protected void onPause() {
    super.onPause();
    // deactivate receiving
    mNfcAdapter.disableForegroundDispatch(this);
}


private void logError(String msg) {
    Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    Log.v(LOG_TAG, msg);
}

@Override
public void onNdefPushComplete(NfcEvent arg0) {
    Log.d(TAG, "Push complete");
}

@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    Log.d(TAG, "Creating massage");

            String text = "asdfgh";

    // Nachricht vorbereiten.
    // String text = "Hello NFC World!";
    NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
            MIME_TYPE.getBytes(), new byte[0], text.getBytes());
    NdefRecord[] records = { record };
    NdefMessage msg = new NdefMessage(records);
    return msg;
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:11:24+00:00Added an answer on June 5, 2026 at 4:11 am

    I post this Answer for you, that you can accept it.

    The solution was the wrong Mime-Type inside Android-Manifest. It must be the same as the NdefRecord defines

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing an activity that responds to the RecognizerIntent . Among others this
I am finishing implementing an application, which has inside activity for sending a message
I have created an activity implementing on touch listener and onclick listener . Both
I am implementing a session manager for my application. Each time an activity is
I am implementing an activity indicator in my application. In my application on button
I am implementing an Android Activity from which other Activities will be derived from.
hi i am implementing gallery application in this gallery circular order draging left to
I am implementing a simple alert view with activity indicator to show to the
I'm implementing this application where i need to pause it when the back key
I am implementing List view in my Activity. I am showing image in first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.