Autofill service doesn't show up suggestions automatically - android

I only get autofill suggestions after I make long press on input field and select 'autofill'. As I've read in other answers, this forces requestAutofill. I've enabled my autofill service like so:
First, check if it's available and set autofill hints for input fields:
autoFillService = requireContext().getSystemService(AutofillManager::class.java)
autoFillService?.let { autoFillServiceEnabled = it.isEnabled }
Timber.d("Autofill service is $autoFillServiceEnabled as $autoFillService")
if (autoFillServiceEnabled && autoFillService?.isAutofillSupported == true) {
setAutoFillHints()
}
Hints are set like this. I've also set android:importantForAutofill="yes" in xml:
firstNameEditText.setAutofillHints(HintConstants.AUTOFILL_HINT_PERSON_NAME_GIVEN)
Finally, I request autofill service on input field when onFocus event occurs:
autoFillService?.requestAutofill(fieldView)
Why it doesn't show autofill suggestions automatically? Have I missed something?

Related

Receive barcode scanner Device result in android

I am trying to receive the scanned barcode result from a device paired via (Bluetooth/USB) to an android device.
so many topics said :
most plug-in barcode scanners (that I've seen) are made as HID profile devices so whatever they are plugged into should see them as a Keyboard basically.
source
So I am using this code to receive the result of the scan:
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (viewModel.onTriggerScan()) {
//1
char pressedKey = (char) event.getUnicodeChar();
viewModel.addCharToCode(pressedKey);
//2
String fullCode = event.getCharacters();
viewModel.fullCode(fullCode);
//check if the scan is done, received all the chars
if (event.getAction() == EditorInfo.IME_ACTION_DONE) {
//does this work ?
viewModel.gotAllChars();
//3
String fullCode2 = event.getCharacters();
viewModel.fullCode(fullCode2);
}
return true;
} else
return super.dispatchKeyEvent(event);
}
Note: I don't have a barcode scanner device for the test.
which code will receive the result ?? (1 or 2 or 3 ?)
You won't ever see an IME_ACTION_DONE, that's something that's Android only and an external keyboard would never generate.
After that, it's really up to how the scanner works. You may get a full key up and key down for each character. You may not, and may receive multiple characters per event. You may see it finish with a terminator (like \n) you may not- depends on how the scanner is configured. Unless you can configure it yourself or tell the user how to configure it, you need to be prepared for either (which means treating the data as done either after seeing the terminator, or after a second or two once new data stops coming in.
Really you need to buy a configurable scanner model and try it in multiple modes and make ever mode works. Expect it to take a few days in your schedule.
Workaround solution but it works 100%.
the solution is based on clone edittext (hidden from the UI), this edit text just receives the result on it, adds a listener, and when the result arrives gets it and clears the edittext field. An important step, when you try to receive the result(trigger scan) make sure that edittext has the focus otherwise you wil not get the result.
Quick steps:
1- create editText (any text field that receives inputs) in your layout
2- set its visibility to "gone" and clear it.
3- add onValueChangeListener to your edittext.
4- focus your edittext when you start trigger the scan
5- each time you the listener call, get the result and clear edittext
Note: never miss to focus your edittext whenever you start trigger scan.
Note: this method work(99%) for all external scan device and any barcode type.

16: Skipping password saving since the user is likely prompted with Android Autofill

I am integrating google smart lock in my android application but in some devices i am getting this error when trying to save credentials to google. I am using following code to save credentials -
Credential credential = new Credential.Builder(email)
.setPassword(password)
.build();
saveCredentials(credential);
After search on google for this solution found that need to disable auto-fill feature in application to save the password.
Try 1 - Put the following code in activity for commit autofillmager in specific activity and disable autofill. But it is not working.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillManager autofillManager = getSystemService(AutofillManager.class);
autofillManager.commit();
getWindow()
.getDecorView()
.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
}
Try 2 - Put following in properties in EditText
android:longClickable="false"
longClickable should stop autofill but it is not working.
android:importantForAutofill="no"
Also try with importantForAutoFill but it is also not working.
I removed all the code for manual saving and just added
android:autofillHints="username" for login field and android:autofillHints="password" for password field in the sign in form. Password saving dialog appears all the same, thanks to the Android's Autofill service.

Read other application WindowManager(System Alert) Alert in android?

I am building an android application where I want to read WindowManager(System Alert) Alert Text that is trigger from some other application.
Suppose there is some application like true caller and after the end of each call this application display some information of that particular phone number in WindowManager(System Alert) of android and I want to read all this information related to that phone number which is displayed in WindowManger(System Alert) using my application.
Is there any way to read or to get view child of WindowManger(System Alert) Alert dialog trigger by other application.
Think one way would be to write an accessibility service (https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html) and hook to some accessibility events. Maybe TYPE_WINDOW_STATE_CHANGED?
You can try setting AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS in the accessibility service and listen for events like
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: {
AccessibilityNodeInfo nodes = getRootInActiveWindow();
String nodeText = nodes.getText();
String nodeContentText nodes.getContentDescription();
// Also you could cycle through the children repeating the same
// As an example only taking the first child, you could
// loop through or use recursion
AccessibilityNodeInfo firstNode = nodes.getChild(0)
String nodeTextFirstChild = firstNode.getText();
String nodeContentTextFirstChild = firstNode.getContentDescription();
}

Initialize Instabug without showing hint prompt

I need to initialize Instabug in my Android application but do now want it to show the hint prompt saying "Shake your device etc." when user just opened the app. Instead I want to show that after user has already logged in.
I initialize Instabug with the following code:
new Instabug.Builder(this, instaKey)
.setInvocationEvent(InstabugInvocationEvent.SHAKE)
.setShakingThreshold(1100)
.build();
So is there a way to disable that hint prompt in a first place place?
I tried to set .setPromptOptionsEnabled(false, false, false) but it seems this does not what I need.
I cannot find any documentation about this.
You can disable showing it by setting false to setIntroMessageEnabled(boolean) API example:
new Instabug.Builder(this, instaKey)
.setInvocationEvent(InstabugInvocationEvent.SHAKE)
.setShakingThreshold(1100)
.setIntroMessageEnabled(false)
.build();
and then whenever the User is logged in you can show the intro message by invoking it manually example:
Instabug.showIntroMessage();
And by the way the .setPromptOptionsEnabled(true, true, true) is used for controlling prompt Options visibility [talk to us, report a bug, send a feedback] as described in the official docs here: http://docs.instabug.com/docs/enabled-features

Detect if voice typing is enabled

I need to display an alert to the user if they haven't enabled Google voice typing from their settings(Language and input -> Google voice typing). Is there someway to detect that setting status?
So i found my answer. There is no official way of detecting wether voice typing is enabled or not. I have managed to get a list of enabled input methods ( keyboard, voice, etc).
String enabledMethods = Settings.Secure.getString(getActivity().getContentResolver(),Settings.Secure.ENABLED_INPUT_METHODS);
There we can see if Google voice typing is enabled or not and we can alert the user to turn it on, however this applies for the default keyboard. Some users use custom keyboards that have their own implementation of speech to text and it doesn't relly on the users settings for Google voice typing. So it will be a false positive for them.
Given that you know the package name of the IME, you can do something like this:
boolean isImeEnabled(String packageName) {
InputMethodManager imm =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
for (InputMethodInfo imi : imm.getEnabledInputMethodList()) {
if (imi.getPackageName().equals(packageName)) {
return true;
}
}
return false;
}

Categories

Resources