android : listening to keypress from background - android

I read many answers on this topic and this is what i have understood
It is not possible to get any hardkey (home,menu,back,etsc ) press events from a service. It is not delivered to any service
For key camera button and media control broadcast events are sent if these applications are not already in the foreground.
So i need to conclude that it is not possible to launch an app by pressing a hardkey or a combination of hardkeys ie ( like home key 2 times or menu key and then back key ) ?
If this is the case how is samsung launching Vlingo when home key is pressed 2 times.
How this functionality is added to samsung galaxy
thanks a lot for your time and help

The Service Can not get the KeyEvent.
Sumsung can do it directly with the system rom. But we can not.

Related

Detect long press on keyboard key (Ionic, Android)

I have an Ionic (5) app and I want to detect a long press on a key (keyboard) when the app is running on a mobile device (I'm testing on Android).
I added (keyup) and (keydown) to a ion-input, and when I run the app on browser I'm able to get the time difference between the first keydown event (if I long press on a key, keydown is firing multiple times) and the single keyup event that i receive when the key is released.
Unfortunately, this solutions isn't working on mobile (Android), I only receive one keydown event and one keyup event that fire almost at the same time, even if I press the enter key for more than 5 seconds or so.
I don't think any code is needed, since this one is more a conceptual question.
How can detect a long press on a mobile keyboard?
In android this isn't going to work. It's just not how the keyboard interface happens. By and large, keyboards don't actually send key events in Android. They send commitText messages, which just send a string to the text field. Anything turning it into key up and key down events is in the Ionic framework. Since the keyboard doesn't send key events, the app can't know how long they pressed the button. They keyboard doesn't send that info. So the Ionic framework that's making the key events can't give you that info either, there's no data for it to extrapolate from.
You're going to have to come up with a different UX design, this will never work on Android.

Android Wake up app on bluetooth keyboard key pressed

I'm trying to develop an app that recognizes when a paired bluetooth keyboard's key is pressed and wakes up the app with certain action. The bluetooth device in particular is the Selfie Remote Shutter (this one, no ads intended: http://www.ebay.es/itm/like/361219097614) and it's recognized by the device as a bluetooth keyboard. It sends two different events which the SO in Android identifies as key volume up pressed and enter key pressed.
I've declared a receiver for my app and tried to listen to every bluetooth action in order to identify the command sent from the keyboard to my device, capture that event and trigger certain method in my app, even if it's not open.
I don't know how to achieve this, since when the app is opened, I can override the onKeyDown event and recognize which "key" has the bluetooth keyboard pressed, but can't figure how to achieve that with the app closed. Maybe some intent-filter?
Thanks in advance!

Android- Using Power Button as trigger to start application

I am trying to build an app with the ability for it to be shown over Lock Screen when the physical Power button is pressed say 2 times in quick succession or long pressed.
So far I have figured out that I need a-
1) SERVICE- I need a Service that should intercept the Power buttons pressing 2 times / long press- whether the device is locked or not
2) RECEIVER- User Broadcast Receiver to capture the broadcast intent from service and launch my main activity.
A lot of questions on SO are similar but none of them address how to do this because-
The Service cannot have methods to detect Key Events & as a result need to find some other way to figure out when Power key is being pressed. The suggested alternate is to use SCREEN ON and SCREEN OFF intents. But using them causes a problem if the service is running in background and the Screen is woken by some other app, eg an incoming call.
I have seen few apps which use Power button to start apps or activity.
1) Press It- https://play.google.com/store/apps/details?id=com.incrediapp.press.it.macro.creator.time.saver&hl=en
2) Power Button Flashlight- https://play.google.com/store/apps/details?id=com.brink.powerbuttonflashlight&hl=en
Any ideas on how to start an app/activity over the press of Power buttons?
And then show it over the lock screen.
Short answer: You can't! The system wasn't build that way.
How ever many times when someone says: "You can't" he actually mean you can't without hacking it...
So here is an idea for a hack for you:
As you mentioned, services can't listen for key events, but Activity can. So activity is your answer.
Start your activity when the screens goes off, and kill it when it comes back. Also make it transparent just in case you get out of sync and you don't want to be spotted.
Now you got an easier problem to solve, how to trigger the power button from inside your activity.

How to make an app or specific activity launched when pressing menu button or power button etc (e.g like 3 times)?

how to make an activity in specific app(security app) started when pressing (menu or any other of the device buttons), what i should do?, i'm already have BroadcastReceiver in my app(to read SMS).
I'm new to android, so from where i should start? Please help me.
Edit: In my phone(Samsung) if i press too long on menu button one of google apps started(launched).
According to the official Android documentation (http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_HOME): Key code constant: Home key. This key is handled by the framework and is never delivered to applications.

Key events in Android services

I've made some research concluded that afaik I can't have an Android service for key events capture. But - maybe some will have any workaround. I have a player application, which i want to play/pause using a special button on my earphones (included for my samsung galaxy S). This is button for reciving and ending phone calls set on phones cable.
Ive tested this button - it equals KeyCode.KEYCODE_BUTTON_B const (79). And it can be handled when my player is on screen, but I'd like to play/pause also when my phone is locked (with screen off). Do You think this is possible?
For call reciving I think android uses a trick: when someone calling, the screen goes active, and the call-reciving activity can handle key events (I think - this is how it's work, but I can be wrong).
I have no idea - how to play/pause my app using this button.
I don't think there is any real good way to achieve what you want to do from the application level. However one possible solution I can come up with is this:
Listen for screen off and on Intents. When you receive SCREEN_OFF start up a "blank" activity that does nothing but listen for your button press and passes it along to your music service.
When you recieve SCREEN_ON finish() this blank activity.
I don't know for sure that this approach will work, but I used something similar to be able to listen for volume button presses while the screen was off.
Note about listening for SCREEN_OFF and SCREEN_ON intents. When I did this I had to set the filter for my receiver in java code rather than in the manifest. For some reason when I set the intent filter from the manifest it wasn't receiving those intents properly.

Categories

Resources