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.
Related
I want to try to make an Android alarm app that is impossible to stop. In other words, it keeps going for a predetermined amount of time, even if the user presses the power button, tries to reduce the volume, or anything else.
It does not seem feasible to me, but since I have very little Android experience, I'd like to know if something like that is theoretically able to be done. Thanks.
This question has been addressed on SO here: Override Power button just like Home button
.
There are several answers in the link that will give you options and get you 90% of the way there, but no answer will cover all devices/scenarios. The accepted answer in the link puts it best:
The Android system, as far as is documented, defines (a physical button press) as a
broadcast action. Following the publish-subscribe pattern of message
propagation, this message will notify all concerned parties of this
action. Because this message is sent by the system, because the
message stack is managed by the system, and because the message is
also received by the system, your code simply (cannot be) injected in the
right place to block the reception of this message.
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.
I am writing a metronome app, I have the sound running from a service which I would like to keep running when the user is outside the app (browsing etc) and hasn't made a conscious effort to press the stop button.
It seems I should be using startForeground() as it's not the kind of thing you want in the background without paying attention to, and I really don't want the service to be killed at any time. Ideally I wouldn't be showing the notification while the app is in focus though. I notice that the Google Play Music app works this way, it only shows the notification when outside the app. Is anyone able to tell me how they have done this, I would find it hard to believe they wouldn't be using startForeground() after reading all the documentation stating you should be using it for this sort of app?
On the other hand, is this really desired behavior? It seems good to me, but I noticed that pretty much every other app I use with a long running service (HTC's music app, Navigation, few others) shows the notification icon at all times, whether in the app or not. I am interested in what is considered correct behavior. Any help much appreciated, thanks.
Is anyone able to tell me how they have done this
They probably call stopForeground() when one of their activities returns to the foreground, and startForeground() when they think the user has left (e.g., onUserLeaveHint()).
I am interested in what is considered correct behavior.
I do not think there is a definitive "correct behavior" in this area. It is easier to do what the other apps do and leave the Notification around, until the user indicates that they no longer want the background work to run.
Note that while you may want "to keep running when the user is outside the app", the user might not. Certain types of apps (e.g., music players) can safely assume that the user wants the audio to keep going; a metronome, IMHO, does not rise to that level. Please allow the user to configure this behavior, such as through a SharedPreference.
My App sends out GPS data with a timer. Sometimes I block the screen.
Now with some phones and only sometimes I have the problem that the OS somehow blocks the data packages and only releases them later, when the screen is unlocked. The messages still are getting sent from the app but only stopped in android.
Anybody have a Idea why that happens and how I can stop it?
Is it possible that those devices are going to sleep (or sending the radio to sleep)? Have you tried setting a wakelock to prevent this? https://developer.android.com/reference/android/os/PowerManager.WakeLock.html
I suspect your application goes to sleep, or your wifi. There are applications specifically designed to keep your wifi alive, so i suspect it does sleep. Were i to create the wifi, i would definitely make it sleep when there wasnt anything to say.
To test download one of the apps. That and write to a log file when your application is going to sleep.
Sorry i couldnt give a specific answer. Id have posted this as a comment, but im too new to be able to do that.
The primary purpose of my app is to change a smart phone into a sort of smart pager (there is an associated web app, but that's not the purpose of the Android app). I use the Notification system built in to Android to handle alerting the user that they have received a page.
My problem is that the clients want:
The notification ringer to ring forever until acknowledged (easily accomplished with FLAG_INSISTENT)
An easy way to silence the ringer with 1 push of a button. It is really not always feasible due to the nature of their work to press the power button, slide to unlock, and drag down the notification bar. I need to replicate the behavior of a pager.
I need to find a way to satisfy the 2nd requirement. It looks like I can hook into keypresses if I've got an activity running, but of course, when a notification is received, the screen will probably be off. I am looking into this currently, but I was wondering if anyone had some guidance in the meantime.
Does anyone have ideas on how I could accomplish this goal? Are there alternative ways to listen for key presses, or some creative combination of flags that could get me there?
Techniques that would normally be frowned on for Market apps are completely on the table, since the phones are owned by my employer and will only be used by other employees. I just want to avoid using private or deprecated APIs to make switching phone models easier for the developer who eventually inherits this project.
Thank you to everyone for reading!
Does anyone have ideas on how I could accomplish this goal?
You'd have to hold a WakeLock, specifically a FULL_WAKE_LOCK, in order to respond to button presses. This means that battery life will be sucktastic, unless you put some time limit on that (e.g., hold the WakeLock for a minute or two, but otherwise assume the user's not near the device, so don't keep it awake).
You would also need to try to interrupt the keyguard with KeyguardManager. I have not done this so I do not know all of the details. Your "watch for the magic button" logic would have to be in the activity that appears on top of the keyguard.
Also, bear in mind that not all Android devices have physical buttons -- in fact, I would not be the least bit surprised if the whole physical button metaphor goes "poof" with Ice Cream Sandwich later this year. Hence, the button in question really should be an on-screen Button for future-proofing.