I want to reassign event, when user send KEYEVENT_SEARCH. Now it just start search activities in applications and if you press it second time - it doesn't do anything. I have to redefine the event so that the first click opens the search, and the next time it closes. Where can I find android push responses? I try edit it in frameworks/base/core/java/com/android/internal/policy/PhoneFallbackEventHandler.java , but it doesn't works.
Android keys are processed in the following sequence:
PhoneWindowManager:
interceptKeyBeforeQueueing
interceptKeyBeforeDispatching
Activity: onKeyDown/onKeyUp. App can override the function to handle keys.
PhoneFallbackEventHandler: onKeyDown/onKeyUp
Currently, the search key is handled in 2. When handling search key in onKeyUp, firstly check whether the search dialog is launched, then choose to startSearch or closeSearch.
Related
We have a Barcode scanner, to scan 3 types of barcodes (CODE93, QR, Datamatrix).
The scanned data from Barcode scanner gets placed in the cursor point.
For displaying only the QR code data, even if other code gets scanned into, we need to analyse the received data in the cursor point.
We have found & tried to automate click event, but weren't able to automate the same.
Can someone help us with a program to solve the same?
There is a TextWatcher listener available in the sdk to get the value of an edittext whenever it's value changes. There you can get the changed value and perform any analysis needed. Automating a click event doesn't make any sense. Whatever code you have written inside onclick listener can be called anywhere else if you have put it inside a method of your own. Still if you want to know you can look into this thread Can I click a button programmatically for a predefined intent?
button.performClick()
Before people say this is a duplicate of "check if android is on first run", this question is to check if the activity itself (not the app in whole) is open for the first time.
I have different activities that run Material Tap Target Prompt, so a few pop-ups that explain the buttons and functions.
But I only want it to run for first time users.
Now I tried the following:
if (prefs.getBoolean("firstRun", true)) {
prefs.edit().putBoolean("firstRun",false).apply();
........Do the pop ups
}
But this will set it for the whole app and so when the user gets to the next screen it won't run because the boolean is set to false.
So I am trying to find a way to check if the activity itself is opened for the first time but I can't seem to find anything that would solve this issue.
I thought about using a variable then setting it to 1. But if the users restarts the app, it crashes etc then that var will be reset.
May other option is to create a row in a DB and then check if that is set to 1 or whatever depending on the activity.
But maybe there is an easier way?
Thank you
Why don't you just create preference keys for each Activity. Sample code added below:
if (prefs.getBoolean(MainActivity.class.getCanonicalName(), true)) {
prefs.edit().putBoolean(MainActivity.class.getCanonicalName(),false).apply();
........Do the pop-ups
}
Searched through the internet and couldn't find a god example of achieving the following. There is a Launcher activity. User will be navigated to the launcher activity first and inside that activity , when the user says a certain word like "Start" or something like that the app should navigate the user to another activity. I've gone through a set of tutorials , and I've seen some similar questions at SO but none of them make sense to me. What will be the best approach to achieve this ?
Basically what you have to do is
build a framework/module to handle Speech Input (speech-2-text)
Depending on Input by user, perform an action
I have a code that requires two edittexts, this information is used to display direction on a map. How can I submit this data automatically on activity start, without the need of a button.
Side question, is there a way to hide these edittexts? To prevent further manipulation by users.
EditTexts can be either disabled using editText.setEnabled(false); or hidden using editText.setVisibility(View.INVISIBLE);.
If you want to execute code on an activity start just write it into the onCreate(...) method.
Is it possible to have my android application start a method from pressing of the convenience key when the application in focus?
On my phone the convenience key is a button located on the right hand side of the phone. I would like to be able to know if the user presses any of the buttons on the phone, even the volume would work.
You are welcome to override onKeyDown() on your Activity and watch for a KeyEvent of interest. Note that not every key in the KeyEvent JavaDocs is accessible this way (e.g., power). Also note that it is possible that some specific View that is aware of these keys might consume the event first, though that is relatively unlikely for anything that matches your description of a "convenience key".