Bluetooth discovery without prompt in Android -


i able turn on/off bluetooth without prompt using following code. requires bluetooth , bluetooth_admin permissions.

boolean isenabled = bluetoothadapter.isenabled(); if (enable && !isenabled) {     return bluetoothadapter.enable(); } else if (!enable && isenabled) {     return bluetoothadapter.disable(); } 

but didn't find way set bluetooth discoverable without user prompt. it's wired prompt every time user. there no "don't ask me again" feature afraid. there way make bluetooth device discoverable? don't care duration. device not rooted.

more info

i found source code of bluetoothadapter.java , has public method named setdiscoverableduration. why can't access it? why public methods hidden in api documentations? how did that? methods public.

finally have found way using reflection.

method method; try {     method = bluetoothadapter.getclass().getmethod("setscanmode", int.class, int.class);     method.invoke(bluetoothadapter,bluetoothadapter.scan_mode_connectable_discoverable,120);     log.e("invoke","method invoke successfully"); } catch (exception e){     e.printstacktrace(); } 

warning: above method trying invoke hidden method. in future maybe not work.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -