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

  • Home
  • SEARCH
  • 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 7875759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:03:06+00:00 2026-06-03T03:03:06+00:00

I am in a android beam project right now. And I copied a test

  • 0

I am in a android beam project right now. And I copied a test class from android developers.

My problem is to send the correct data. If I connect (p2p) with another device and press “Tab to beam” only a URI to the android market arrives.
But if i open my browser, connect and tab, the current url from the browser arrives.

How can I tell android which view or text should be send? I didn´t get it. I just want to send a simple string “hello!” e.g.

This is the code:

package peer.to.peer;

import java.nio.charset.Charset;
import android.app.Activity;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcAdapter.CreateNdefMessageCallback;
import android.nfc.NfcAdapter.OnNdefPushCompleteCallback;
import android.nfc.NfcEvent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class Peer2peerActivity extends Activity implements     
CreateNdefMessageCallback,     OnNdefPushCompleteCallback {
   private Button sendButton;
   private EditText textfield;
   NfcAdapter mNfcAdapter;
   private static final int MESSAGE_SENT = 1;


   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);

          //initialisierung
          sendButton=(Button) findViewById(R.id.button);
          textfield= (EditText) findViewById(R.id.textfield);

          //mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

          //if(mNfcAdapter==null) toast("NFC ist nicht vorhanden");
          //else toast("NFC ist  vorhandne");


          toast("start");

          sendButton.setOnClickListener(mTagWriter);
   }

   //lokaler OnClickListener für den Button
   private View.OnClickListener mTagWriter = new View.OnClickListener() {
    public void onClick(View arg0) {
        // Write to a tag for as long as the dialog is shown.
        //disableNdefExchangeMode();
        //enableTagWriteMode();

          toast(textfield.getText().toString());
    }
   };
   //notification-methode
   public void toast(String text){
          Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
   }

   public void onNdefPushComplete(NfcEvent arg0) {
          // A handler is needed to send messages to the activity when this
    // callback occurs, because it happens from a binder thread
    mHandler.obtainMessage(MESSAGE_SENT).sendToTarget();         
   }

   public NdefMessage createNdefMessage(NfcEvent event) {
    String text = (textfield.toString());
    NdefRecord uriRecord = new NdefRecord(
              NdefRecord.TNF_ABSOLUTE_URI ,
              "http://www.google.de".getBytes(Charset.forName("US-ASCII")),
              new byte[0], new byte[0]);
    NdefMessage msg = new NdefMessage(
            new NdefRecord[] { uriRecord
    //createMimeRecord("text/plain", text.getBytes())
     /**
      * The Android Application Record (AAR) is commented out. When a device
      * receives a push with an AAR in it, the application specified in the AAR
      * is guaranteed to run. The AAR overrides the tag dispatch system.
      * You can add it back in to guarantee that this
      * activity starts when receiving a beamed message. For now, this code
      * uses the tag dispatch system.
      */
      //,NdefRecord.createApplicationRecord("com.example.android.beam")
    });
    return msg;

   }

   /**
 * Creates a custom MIME type encapsulated in an NDEF record
 *
 * @param mimeType
 */
public NdefRecord createMimeRecord(String mimeType, byte[] payload) {
    byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));
    NdefRecord mimeRecord = new NdefRecord(
            NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
    return mimeRecord;
}

/** This handler receives a message from onNdefPushComplete */
private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
        case MESSAGE_SENT:
            Toast.makeText(getApplicationContext(), "Message sent!",     Toast.LENGTH_LONG).show();
            break;
        }
    }
};
}

Thanks in advance

Berry

  • 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-03T03:03:08+00:00Added an answer on June 3, 2026 at 3:03 am

    You’re getting the URI because the first record is a URI record that points to google.de. Replace uriRecord with the call to createMimeRecord() and you should get text sent with the mime type set to text/plain.

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

Sidebar

Related Questions

android how to Send a String of data from an android mobile to server
Android 2.3 platform contains a SIP demo project. I want to test this project
Android Java project, minimal code to reproduce the problem: Constants.java : package alex.restaurantfinder; public
Android 3.2. Attempting to use Switch (http://developer.android.com/reference/android/widget/Switch.html) in my project. Switch.class is not found
Android passing multiple data to notification when i click on notification its only open
Android's messaging app, located in projects/platform/packages/apps/Mms.git has a class called RecipientsEditor. I would like
I'm trying to implement Android Beam in an app that will not be distributed
I'm playing around with Beam and NFC but I only own one android device,
Android VideoView works when I disable rtsp authentication from server side. But when authentication
Android - when getting images from Gallery, they are with wrong orientation. For example,

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.