how to turn Bluetooth on/off with J2ME?

2019-06-27 23:58发布

问题:

I want to write a program in J2ME to turn the Bluetooth on/off automaticly in a certain time without the user permission.

I'v been looking for a while but I couldn't find an answer.

回答1:

Some phones will automatically switch bluetooth ON when a MIDlet starts using the Java ME Bluetooth API.

Other phones will not.

AFAIK, there is no Java ME API to switch bluetooth ON/OFF.

I have yet to find a mobile phone that automatically switches bluetooth OFF after some time of inactivity.

Any way you find to do this (I'm sure it's doable in Symbian OS C++, for example) will be platform-dependant.



回答2:

There is definitely no way to programmatically switch your Bluetooth on and off in Java ME. However what may be useful is to switch between discoverable modes:

LocalDevice.getLocalDevice().setDiscoverable(DiscoveryAgent.GIAC);

to be discoverable, and

LocalDevice.getLocalDevice().setDiscoverable(DiscoveryAgent.NOT_DISCOVERABLE);

to hide from other devices. It doesn't save battery, but it does make things that little bit more secure I guess.



回答3:

No way. We cannot be able to automatically turn on/off bluetooth in java & j2me. Better you refer to the documentation of JSR 82