简体   繁体   中英

Launch my Google Action from the Android App

I've been trying for some days to open the google assistant with one button (done) and sending a query to open my google action (not done). This seems impossible so far. Any help? Btw, I am using Xamarin, but android answers are very welcomed too.

        Intent intent = new Intent(Intent.ActionVoiceCommand);

        String queryString = "Talk to my google action";
        intent.SetClassName("com.google.android.googlequicksearchbox",
                            "com.google.android.googlequicksearchbox.SearchActivity");
        intent.PutExtra("query", queryString);
        intent.SetFlags(ActivityFlags.NewTask);

        StartActivity(intent);

To do this, you wouldn't send a text-based query to search. Rather, in the Actions Console you will seeAction Links .

For a given Action, you will see the Links section. When you enable it, you will be given an HTML code snippet that you can use on a website or even in an Android app.

https://assistant.google.com/services/invoke/uid/<action-id>?hl=en

You can use this URL in your Android app by opening it. This will trigger the Assistant to capture the URL and open your Action.

String url = "https://assistant.google.com/services/invoke/uid/<action-id>?hl=en";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);

在此处输入图片说明

Do you want to achieve the result like following GIF? 在此处输入图片说明

I change the Intent.ActionVoiceCommand to Intent.ActionWebSearch

Here is my code.

  private void Button1_Click(object sender, System.EventArgs e)
    {


        Intent intent = new Intent(Intent.ActionWebSearch);
        intent.AddCategory(Intent.CategoryDefault);
        string queryString = "Talk to my google action";
        intent.SetClassName("com.google.android.googlequicksearchbox",
                            "com.google.android.googlequicksearchbox.SearchActivity");
        intent.PutExtra("query", queryString);
        intent.SetFlags(ActivityFlags.NewTask);

        StartActivity(intent);

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM