Turning off Bluetooth when exiting an application - android

As an introduction to my question, I'll tell you that I've searched around the correct way to do things but still didn't find an answer.
I saw in many questions asked in stackoverflow, that exiting applications in Android is done simply by clicking the 'home' button. I saw some people say that it is not a common use to have an 'exit' button on your app.
Here comes my question. Suppose I turn on the Bluetooth coonection in my app, so that two players can play one against each other with two phones/tablets. Now, they want to go out or they want to go on in their lives. How can I turn the Bluetooth off? is there a timeout for application that does this for me? Should I start a downtime counter to turn the Bluetooth off? What if the user decided to go out to read an SMS and then come back to the app, discovering the bluetooth is off?
In other words, what is the correct manner to deal with shuting down Bluetooth when it is not needed any more with out interfering the user?
Sorry for the long question, I just want to make myself clear.
Thanks,
AJ

You can override the onPause() method in your activity to disable bluetooth, and override the onResume() method in your activity to enable it again.
However, I would not recommend this. For starters, it takes a good second of time to switch the hardware on/off. Also, what if the user is using some other bluetooth connected device? Pausing your app would cut that connection off. What if bluetooth was already on when the user starts the app? They probably wouldn't want your app changing that.
My recommendation is when you start your app, look and see if BT is enabled. If it is not, prompt the user to turn it on. If you're really set on cleaning up after yourself, you could add a checkbox to the prompt I just mentioned, that says something like "Disable it again on exit", and let them choose if they want that.

Related

How to disable Accessibility "TalkBack" in your application?

My application uses TTS (text-to-speech) Engine, and the conflict I am running into is that Accessibility Talkback settings override anything TTS tries to say. I would like to disable the phone's talkback option if using my application.
Is there some sort of permission to handle this? I have not been able to find anything.
I know it's late, but I had the same problem few days ago.
If you want to "ovverride" the TalkBack with your own TTS engine you can simply add:
android:importantForAccessibility = "no"
to each view inside your Layout.
Now you can call your TtsSpeak() method inside your Activity.
IMPORTANT: This does not turn off the TalkBack App, but it will allow you to have a little bit more control over your App.
That is not allowed unless the phone is rooted. The accessibility functions on the phone are not to be changed by a developer, as a blind person may need them to use the phone.
Lg P875: having tried out Accessibility mode, the phone locked me out from scrolling - thus unable access Availability facility to reverse process. Nothing in User manual.
By accident I found selecting Settings icon, tap twice followed by long push on same icon. The screen released and I was able to terminate Talkback key. All back to normal, no thanks to LG user manual

How to kill an app with the hard buttons in Android Smartphone?

In iOS device, we can kill a foreground app with the hard buttons. We can do it by the way written below:
1. Push down the power button and keep pushing
2. Wait for the power-off screen is shown
3. Push the Home button and keep pushing.
If we use this way, the data of the foreground app that is not saved will go away.
Usuually we only use this method when our device freezed, but some game players around me use it for other purpose.
But I dont know the same method in Android.
Do you know the method to kill the foreground app with the hard button, and without running onPause()?
If you know, could you tell me it?
*I am a (private) junior high school student in Japan. I think I am better at using English than public school students, but there may be some grammer mistakes, wrong collocation, or spelling mistakes. So please read carefully.
Any answers or hints will be thanked.
I'm waiting for your good answers or hints!
If you mean killing an application screen progrmatically use -
finish();
once you leave the activity for another screen, if you mean physically (using the device physical buttons) than a long push on the home button will show you all the apps running on the foreground swipe them to the left or to the right in order to terminate them
However some apps uses services in order to fetch data or make logic operations which are unbound to the UI for those you should go to the "Application manager" on your device setting and kill them manually (by pressing stop) you can also use this app.

capture hard-button events when phone is locked?

i am currently collecting information, if it is possible to make some kind of quickdraw-application for emergency purposes; i want to get the device to start a customized camera-intent once some certain key-combo is pressed.
I have check quite some information on the topic already, but it is still not clear to me how doable this whole idea is.
So far i figured, that it is not meant to be by android-design. My first idea was to build some kind of InputService and make it teach the hard power-button to listen for a triple-click. But the Services arent allowed to catch KeyEvents. So, the volume-button is out of the equasion aswell.
Then i came across the idea reacting on the SCREEN ON/OFF event, but 80% of the ppl say that it is not going to work, while 20% state, that they got it. But im not really sure if they really did it.
Last but not least the question, if it is possible to launch this customized-camera-intent/application out of the locked mode.
resumé: i need to check if its possible in general to launch this camera-app (that does some quick fotos for emergency purposes) while phone is in the pocket in lock-mode. Anybody got some opinion for me? thx
The solution is to setup a BroadcastReceiver that is listening for the SCREEN_ON-Event. I did this one inside a backgroundservice that was waiting for at least two SCREEN_ON-Events within a short period of time. (less than two events obviously can't work)...
The Service then dismissed the Keyguard and was able to even pass past password/gesture and run the App. Funny fact: closing the app does pop back to desktop still beeing logged in.
I did this at Android 4.2.. Sources told me that dismissing the keyguard is not working with current Android-versions no more.

Simulating mouse clicks from service

I am looking forums for two days now and can't find the answer. I am new to android and i have a problem. I need to have a small server service in backround (which i have) that gets coordinates for example. With that coordinates i must simulate (make) a click on the active activity...
It should be service for controling the android from the computer. The computer client aplication sends some information like pressed key or mouse click and the service gets it and performs action on active activity.
Is there any way to do that , some example or something ? Thank you
This is not possible due to obvious security risks.
If you're looking to test your activity, have a look at TouchUtils:
http://developer.android.com/reference/android/test/TouchUtils.html

How to properly kill an Android activity, that isn't a background process

There seems to be a lot of controversy about how to stop applications in Android, so I'll explain what I'm trying to do and why in hopes that I can receive some guidance on how to properly implement the functionality I'm looking for.
I got tired of plugging my phone into power when I get into the car, connecting the headphones, turning BT on, turning WiFi off, and then launching "Car Home" because my dock doesn't do so automatically - it's just a piece of plastic mounted to the dash.
So my application automatically does these things when I connect power - and when I disconnect power, it turns BT off and WiFi back on, but unfortunately, Car Home is still running.
I want to automate the entire process, so I never have to launch (or shut down) Car Home, and make getting in and out of the car a little less frustrating.
I know Froyo introduces ActivityManager's killBackgroundProcesses method, but this doesn't seem to work for me. It does seem to be focused around background processes, but what I've read online seems people want to use it to stop foreground applications.
I've also tried restartPackage from Eclair unsuccessfully, so I'm looking for advice.
What is the best way for me to tell the "Car Home" application to stop specifically because power is disconnected and I'm getting out of the car, without me having to navigate to it's home page and click "Exit"?
Have you seen UiModeManager?
This class provides access to the system uimode services. These services allow applications to control UI modes of the device. It provides functionality to disable the car mode and it gives access to the night mode settings.

Categories

Resources