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

Android-自动填充另一个应用程序的文本字段,android,textfield,autofill,Android,Textfield,Autofill,我正在实现一个Android应用程序,负责与其他服务(如凭证)进行一些数据交换。然后,我想使用这些信息自动填充设备上其他应用程序(如Spotify)的输入字段 有没有办法填充另一个应用程序的输入字段,比如用户名和密码,以消除用户手动输入的繁琐工作 我还注意到,至少在iOS上,Spotify识别出要安装的1Password,并在输入字段旁边显示一个小图标,我可以用它填充1Password中存储的数据字段-这是如何做到的,因为这似乎是我问题的另一个解决方案 提前感谢您可能希望实现自动填充服务 有一个

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

有没有办法填充另一个应用程序的输入字段,比如用户名和密码,以消除用户手动输入的繁琐工作

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


提前感谢

您可能希望实现自动填充服务

有一个现成的示例应用程序,可以让您开始使用

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;
}
@覆盖
public void onFillRequest(FillRequest请求、CancellationSignal CancellationSignal、FillCallback回调){
//从请求中获取结构
List context=request.getFillContext();
AssistStructure=context.get(context.size()-1.getStructure();
//遍历结构,查找要填充的节点。
ParsedStructure ParsedStructure=parseStructure(结构);
//获取与字段匹配的用户数据。
UserData UserData=fetchUserData(parsedStructure);
//构建数据集的表示
RemoteViews usernamePresentation=新的RemoteViews(getPackageName(),android.R.layout.simple\u list\u item\u 1);
usernamePresentation.setTextViewText(android.R.id.text1,“我的用户名”);
RemoteViews passwordPresentation=新的RemoteViews(getPackageName(),android.R.layout.simple\u list\u item\u 1);
passwordPresentation.setTextViewText(android.R.id.text1,“我的用户名密码”);
//将数据集添加到响应中
FillResponse FillResponse=新的FillResponse.Builder()
.addDataset(新的Dataset.Builder()
.setValue(parsedStructure.usernameId,
AutofillValue.forText(userData.username),usernamePresentation)
.setValue(parsedStructure.passwordId,
AutofillValue.forText(userData.password),passwordPresentation)
.build())
.build();
//如果没有错误,则调用onSuccess()并传递响应
callback.onSuccess(fillResponse);
}
类解析结构{
AutofillId usernameId;
自动填充密码ID;
}
类用户数据{
字符串用户名;
字符串密码;
}

事实上,这正是上一集的主题,如果我能解决我的问题,我会研究一下。已经感谢lotwhat is parseStructure和fetchUserData无法解析此代码中的What is parseStructure方法?