gpt4 book ai didi

Android - 自动填充另一个应用程序的文本字段

转载 作者:行者123 更新时间:2023-12-05 00:17:02 33 4
gpt4 key购买 nike

我正在实现一个 Android 应用程序,它负责与其他服务(例如凭证)进行一些数据交换。然后,我想使用该信息自动填写设备上其他应用程序(例如 Spotify)的输入字段。

有没有办法填充另一个应用程序的输入字段,例如用户名和密码,以消除用户手动输入的麻烦?

我还注意到,至少在 iOS 上,Spotify 可以识别要安装的 1Password,并在输入字段旁边显示一个小图标,我可以用它来填充 1Password 中存储的数据中的字段 - 这是如何完成的,因为看起来是我问题的另一种解决方案吗?

提前致谢

最佳答案

您可能想要实现自动填充服务 https://developer.android.com/guide/topics/text/autofill-services.html

有一个随时可用的示例应用程序可以帮助您入门 https://github.com/googlesamples/android-AutofillFramework

Android 将调用 onFillRequest() 方法,让您的服务有机会显示自动填充建议。这是上面链接中的示例代码:

@Override
public void onFillRequest(FillRequest request, CancellationSignal cancellationSignal, FillCallback callback) {
// Get the structure from the request
List<FillContext> context = request.getFillContexts();
AssistStructure structure = context.get(context.size() - 1).getStructure();

// Traverse the structure looking for nodes to fill out.
ParsedStructure parsedStructure = parseStructure(structure);

// Fetch user data that matches the fields.
UserData userData = fetchUserData(parsedStructure);

// Build the presentation of the datasets
RemoteViews usernamePresentation = new RemoteViews(getPackageName(), android.R.layout.simple_list_item_1);
usernamePresentation.setTextViewText(android.R.id.text1, "my_username");
RemoteViews passwordPresentation = new RemoteViews(getPackageName(), android.R.layout.simple_list_item_1);
passwordPresentation.setTextViewText(android.R.id.text1, "Password for my_username");

// Add a dataset to the response
FillResponse fillResponse = new FillResponse.Builder()
.addDataset(new Dataset.Builder()
.setValue(parsedStructure.usernameId,
AutofillValue.forText(userData.username), usernamePresentation)
.setValue(parsedStructure.passwordId,
AutofillValue.forText(userData.password), passwordPresentation)
.build())
.build();

// If there are no errors, call onSuccess() and pass the response
callback.onSuccess(fillResponse);
}

class ParsedStructure {
AutofillId usernameId;
AutofillId passwordId;
}

class UserData {
String username;
String password;
}

关于Android - 自动填充另一个应用程序的文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49395231/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com