java - Bluetooth sending data -


im new @ android development. i'm developing app first of all, have main activity must turn on/off bluetooth, make discoverable, search devices , connect them.

after this, go other activity have text view edittext , send button, can write , send it.

i've got working bluetooth enabling/disabling stuff, need connect new found devices , enter chat type activity , send.

i pretty work, great if can give me example of how can this. code have:

public class btactivity extends activity {  // intent request codes private static final int request_discoverable_bt = 0; private static final int request_connect_device = 1; private static final int request_enable_bt = 2;  // debugging private static final string tag = "bluetoothchat"; private static final boolean d = true;  // name of connected device public static string mconnecteddevicename = null;  // array adapter device list private arrayadapter<string> marrayadapter;  // local bluetooth adapter private bluetoothadapter mbluetoothadapter = null;      @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);          setcontentview(r.layout.main);       final button button1 = (button) findviewbyid(r.id.boton1);     final button button2 = (button) findviewbyid(r.id.boton2);     final button button3 = (button) findviewbyid(r.id.boton3);     final button button4 = (button) findviewbyid(r.id.boton4);     final button button5 = (button) findviewbyid(r.id.boton5);       button5.setonclicklistener(new onclicklistener() {         public void onclick(view view) {             lanzarcomunicacion (null);         }     });        mbluetoothadapter = bluetoothadapter.getdefaultadapter();      if (mbluetoothadapter == null) {                   toast.maketext(this, "bluetooth not available", toast.length_long).show();         finish();         return;        }            button3.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {               if (!mbluetoothadapter.isenabled()) {                   intent enablebtintent = new intent(bluetoothadapter.action_request_enable);                            startactivityforresult(enablebtintent, request_enable_bt);                }          }     });       button2.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {              //llama la dialog activity para visualizar los dispositivos             lanzarbusqueda(null);          }     });          button1.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {                if (!mbluetoothadapter.isdiscovering()) {                                          context context = getapplicationcontext();                                             charsequence text = "making device discoverable";                                         int duration = toast.length_short;                              toast toast = toast.maketext(context, text, duration);                                         toast.show();                   intent discoverableintent = new intent(bluetoothadapter.action_request_discoverable);                          discoverableintent.putextra(bluetoothadapter.extra_discoverable_duration, 300);                  startactivity(discoverableintent);             }                            }     });       button4.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {              mbluetoothadapter.disable();              context context = getapplicationcontext();                                     charsequence text = "turning_off bluetooth";                                       int duration = toast.length_long;                             toast toast = toast.maketext(context, text, 15);                                           toast.show();          }     });  }    public void onactivityresult(int requestcode, int resultcode, intent data) {     switch (requestcode) {     case request_connect_device:         if (resultcode == activity.result_ok) {             connectdevice(data);         }     } }    private void connectdevice(intent data) {     string address = data.getextras().getstring(devicelistdialog.extra_device_address);     bluetoothdevice device = mbluetoothadapter.getremotedevice(address);     btcommunication.mchatservice.connect(device); }    @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.bt, menu);     return true; }   public void lanzarcomunicacion (view view) {     intent = new intent(this, btcommunication.class);     startactivity(i); }  public void lanzarbusqueda (view view) {     intent = new intent(this, devicelistdialog.class);     startactivity(i); } 

}


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -