I am developing an autofill service, it is working well if i use simple remote views for suggestions. If i click on one of the remote views suggested, it fill the input of my external application. And i still get suggestion whenever i click on the input. So my autofill service keeps working.
However if i add some button to remote views, and i click on that button, i no longer get any suggestions from my autofill service. Its like the autofill service is no longer working.
Here is my autoFillRequest funtion, using pending intent.
@Override
public void onFillRequest(FillRequest request, CancellationSignal cancellationSignal, FillCallback callback) {
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.autofill_suggestion_interactive);
remoteViews.setTextViewText(R.id.value, "Suggested Text");
remoteViews.setImageViewResource(R.id.icon, R.drawable.ic_autofill);
Intent intent = new Intent(this, ButtonActionReceiver.class);
intent.putExtra("EXTRA_INFO", "Additional Info");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
remoteViews.setOnClickPendingIntent(R.id.action_button, pendingIntent);
Dataset dataset = new Dataset.Builder(remoteViews)
.setValue(findViewById(R.id.autofill_field).getAutofillId(), AutofillValue.forText("Suggested Text"))
.build();
FillResponse response = new FillResponse.Builder()
.addDataset(dataset)
.build();
callback.onSuccess(response);
}
And this is the button action receiver:
@Override
public void onReceive(Context context, Intent intent) {
String data = intent.getStringExtra("EXTRA_INFO");
AutoDataset dataset = new Gson().fromJson(data, AutoDataset.class);
Log.e("ButtonActionReceiver", "info: " + dataset.getPackageName());
Intent serviceIntent = new Intent(context, FloatingDialogService.class);
serviceIntent.putExtra("EXTRA_DATA", data);
context.startService(serviceIntent);
}
this opens me a floating dialog where i need to put some text, do some execution, and then close it.
After closing the floating popup, i need to get the autofill suggestions again, but i no longer have them.
I tried to request the autofill again manually, but it doesn’t work.
Below is my approach to call manually the autofill service again:
From my floating popup i am calling a broadcast like this:
Intent fillRequestIntent = new Intent("my request to autofill again");
sendBroadcast(fillRequestIntent);
stopSelf(); // Stop the service and remove the floating view
And my broadcast receiver is like this:
public void onReceive(Context context, Intent intent) {
if (intent != null && "my request to autofill again".equals(intent.getAction())) {
Log.d(TAG, "Received new fill request broadcast");
AutoFillServiceImpl myAutofillService = new AutoFillServiceImpl();
myAutofillService.requestNewFill();
}
}
Below is the implementation of the requestNewFill function in my autofill service:
@Override
public void onConnected() {
super.onConnected();
AppLog.e(TAG, "Autofill Service connected");
}
public void requestNewFill() {
AppLog.e(TAG, "Request New Fill");
onCreate();
onConnected();
}
@Override
public void onCreate() {
super.onCreate();
AppLog.e(TAG, "Autofill Service created");
mAutoPreferences = AutoPreferences.getInstance(this);
mUserId = (int) mAutoPreferences.getUserId();
mDatabaseHelper = new DatabaseHelper(this);
}
So, how i can fix that, to get the autofill suggestions again ?