How to make a bluetooth connection in android? -
i want connect device: http://www.rhydolabz.com/index.php?main_page=product_info&products_id=479
i tried using bluetoothchat
class samples. did not work. says unable connect device
.
then tried use following code within try catch
// create socket connection: need server's uuid number method m = d.getclass().getmethod("createrfcommsockettoservicerecord", new class[] { int.class }); socket = (bluetoothsocket) m.invoke(d, 1); socket.connect(); log.d("wcam", ">>client connectted"); inputstream = socket.getinputstream(); outputstream = socket.getoutputstream(); socket.close(); toast.maketext(this, "bluetooth connected", toast.length_long).show();
and following error
04-18 20:45:01.660: w/system.err(6780): java.lang.nosuchmethodexception: createrfcommsockettoservicerecord [int] 04-18 20:45:01.660: w/system.err(6780): @ java.lang.class.getconstructorormethod(class.java:460) 04-18 20:45:01.660: w/system.err(6780): @ java.lang.class.getmethod(class.java:915) 04-18 20:45:01.660: w/system.err(6780): @ com.xpleria.wirelesscontroller.login.onstart(login.java:90) 04-18 20:45:01.660: w/system.err(6780): @ android.app.instrumentation.callactivityonstart(instrumentation.java:1133) 04-18 20:45:01.670: w/system.err(6780): @ android.app.activity.performstart(activity.java:4475) 04-18 20:45:01.670: w/system.err(6780): @ android.app.activity.performrestart(activity.java:4526) 04-18 20:45:01.670: w/system.err(6780): @ android.app.activity.performresume(activity.java:4531) 04-18 20:45:01.670: w/system.err(6780): @ android.app.activitythread.performresumeactivity(activitythread.java:2434) 04-18 20:45:01.670: w/system.err(6780): @ android.app.activitythread.handleresumeactivity(activitythread.java:2472) 04-18 20:45:01.670: w/system.err(6780): @ android.app.activitythread$h.handlemessage(activitythread.java:1173) 04-18 20:45:01.670: w/system.err(6780): @ android.os.handler.dispatchmessage(handler.java:99) 04-18 20:45:01.680: w/system.err(6780): @ android.os.looper.loop(looper.java:137) 04-18 20:45:01.680: w/system.err(6780): @ android.app.activitythread.main(activitythread.java:4424) 04-18 20:45:01.680: w/system.err(6780): @ java.lang.reflect.method.invokenative(native method) 04-18 20:45:01.680: w/system.err(6780): @ java.lang.reflect.method.invoke(method.java:511) 04-18 20:45:01.680: w/system.err(6780): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:817) 04-18 20:45:01.680: w/system.err(6780): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:584) 04-18 20:45:01.680: w/system.err(6780): @ dalvik.system.nativestart.main(native method)
any way how can modify code..?
couple of notes:
a) it's not obvious class of variable d. assume it's bluetoothdevice
b) if assumption 1) correct, can't find method createrfcommsockettoservicerecord(int), because actualy method createrfcommsockettoservicerecord(uuid).
c) it's not clear me, why use reflection method. can call on object directly.
d) there piece documentation says: "hint: if connecting bluetooth serial board try using well-known spp uuid 00001101-0000-1000-8000-00805f9b34fb. if connecting android peer please generate own unique uuid.". think applicable you.
update 1
regarding using directly.
you code should
d.createrfcommsockettoservicerecord(someuuid);
since createrfcommsockettoservicerecord method of bluetoothdevice.
regarding uuid.take @ this:
Comments
Post a Comment