Selasa, 29 Juli 2008. Download Aplikasi Full Screen Caller v3.0.S60v3.SymbianOS9 Gratis. 03.46 Ahmad Darwanan No comments Ahmad Darwanan No comments. Dec 09, 2010 TrekBuddy is a J2ME application to be used with a GPS receiver. Trekbuddy is a J2ME application to be used with a GPS receiver. It is designed to work with every Java-enabled device.
Active1 year, 9 months ago
I'm trying to catch bluetooth state changes with Broadcast Receiver.
My manifest:
Receiver
onReceive
method:I launch app then minimize it by pressing Home button. Go to settings and turn on bluetooth but nothing happens. Though I expect toast and logcat messages. What's wrong here?
Long Smith
Long SmithLong Smith63511 gold badge1212 silver badges2828 bronze badges
2 Answers
In order to catch Bluetooth state changes (
STATE_OFF
, STATE_TURNING_ON
, STATE_ON
, STATE_TURNING_OFF
), do this in your Activity:First, add Bluetooth permission to your AndroidManifest file:
Create a BroadcastReceiver in your Activity or Service:
Create an IntentFilter and register it with BroadcastReceiver to Activity/Service in your
onCreate()
method:Unregister BroadcastReceiver in your
onDestroy()
method:In order to catch changes of discoverability of device (
SCAN_MODE_NONE
, SCAN_MODE_CONNECTABLE
, SCAN_MODE_CONNECTABLE_DISCOVERABLE
), create another BroadcastReceiver and register/unregister to your Activity as I mentioned above. Only difference between those BroadcastReceiver's is first one uses BluetoothAdapter.EXTRA_STATE
and the other one uses BluetoothAdapter.EXTRA_SCAN_MODE
. Here is the example code for BroadcastReceiver to catch discoverability changes:Create filter and register it in
onCreate()
method:Create the BroadcastReciver in Activity/Service to catch discoverability changes:
And lastly unregister it in
onDestroy()
:Note that, you don't need to add any
<intent-filter>
or <receiver>
to your AndroidManifest file, except you need to add Bluetooth permission of course.If you want to catch (
ACTION_ACL_CONNECTED
, ACTION_ACL_DISCONNECTED
, ACTION_ACL_DISCONNECT_REQUESTED
), now you need to add an <intent-filter>
to your AndroidManifest file:Create filter and register it in
onCreate()
method:Then create the BroadcastReceiver in your Activity/Service:
And lastly, unregister:
If you want to read more about state constants, this is from the documentation:
public static final String EXTRA_STATE:
Used as an int extra field in ACTION_STATE_CHANGED intents to request the current power state. Possible values are: STATE_OFF, STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF
![Bluetooth Bluetooth](/uploads/1/2/4/7/124781449/935088841.jpg)
public static final String EXTRA_SCAN_MODE:
Used as an int extra field in ACTION_SCAN_MODE_CHANGED intents to request the current scan mode. Possible values are: SCAN_MODE_NONE, SCAN_MODE_CONNECTABLE, SCAN_MODE_CONNECTABLE_DISCOVERABLE
Mustafa Berkay MutluMustafa Berkay Mutlu1,26211 gold badge1818 silver badges2525 bronze badges
Portable Bluetooth Receiver
Your main problem ;) You cannot use 'switch' for string comparison.
![Aplikasi Bluetooth Receiver S60v3 Aplikasi Bluetooth Receiver S60v3](/uploads/1/2/4/7/124781449/720699631.jpg)
At least not until VERSION_INT 18 (inclusive). Version 19 started with Java 7.
Bluetooth Receiver For Car
chksrchksr