Friday, June 11, 2010

[android-developers] Bluetooth Discoverable

Hello!
I am having trouble with using Bluetooth on the Nexus One. I want to
be able to make the phone go to Discoverable mode without having the
user to give my application permission every 120 seconds or 300
seconds. I have added the BLUETOOTH and BLUETOOTH_ADMIN permissions
on the Manifest file and have looked at the public APIs available for
the android. None of them allow me to automatically enable the
bluetooth to make it discoverable for longer time or doing this
without asking the user. I saw that on many blogs, other developers
have advice others to use the private API's to change the
WRITE_SECURE_SETTINGS to BLUETOOTH_ADMIN_PERM to overcome the problem
with the permissions. Can someone help me find a way to get the app
to turn on the discoverable mode without having to ask the user for
permission each time?

This part of the code belongs to BluetoothService.java:

public synchronized boolean setScanMode(int mode, int duration) {

mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS,
"Need
WRITE_SECURE_SETTINGS permission");
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/server/BluetoothService.java;h=d1dd3110286b5883b675b9359d128886cbdb760a;hb=eclair

The code below requires the user to press YES to have the bluetooth on
discoverable.

Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,
300);
startActivity(discoverableIntent);


Sincerely,
Quynh

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment