Check if bluetooth is enabled using an Android application -
i want check if bluetooth enabled in device using android application. used .isenabled method. there error. found out (by commenting lines) error in .isenabled method. can pls me figure out?
final bluetoothadapter bluetooth = bluetoothadapter.getdefaultadapter(); submitbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { string status = "bluetooth"; if(bluetooth != null) { if (bluetooth.isenabled()) { string mydeviceaddress = bluetooth.getaddress(); string mydevicename = bluetooth.getname(); status = ("address "+ mydeviceaddress + " name" + mydevicename); toast.maketext(getapplicationcontext(), "" + status + "", toast.length_long).show(); } else { status = ("bluetooth not enabled"); toast.maketext(getapplicationcontext(), "" + status + "", toast.length_long).show(); } } else { toast.maketext(getapplicationcontext(), "" + status + "", toast.length_long).show(); } } }
this has worked best me:
/** * check bluetooth. * @return true if bluetooth available. */ public static boolean isbluetoothavailable() { final bluetoothadapter bluetoothadapter = bluetoothadapter.getdefaultadapter(); return (bluetoothadapter != null && bluetoothadapter.isenabled()); }
Comments
Post a Comment