-2

I have three activities in my app and the initial activity is LauncherActivity,this is the starter class. I would like to launch an activity (named MainFormActivity) in my app using voice command. i.e, Google assistant.

Could anyone help me to achieve this?

varsha jeevan
  • 49
  • 1
  • 11
  • Using `Google Assistant` you would like to open your application or via `Voice Command`? Kindly be clear on your question and try to explain bit more. – Kavin Prabhu Jan 02 '19 at 12:22
  • yes,I would like to open my application using google assistant,But the user should provide a voice command to which activity in the application will open.I meant, not the initial activity.may be it will second,third or any other activity. – varsha jeevan Jan 02 '19 at 12:51
  • So can you explain what you have achieved so far? By default, if your app is installed and you tell `Google Assistant` to open, it will open the application. For example my app name is `Record Manager`, now I open `Google Assistant` and tell an action `Open Record Manager` it will default opens the application. But in your case you want to open some specific activities? – Kavin Prabhu Jan 02 '19 at 12:59
  • Yes,I want to open a specified activity in my application. For example, If the Record Manger app contains an activity called Report in its manifest file,(but actually this is not a launcher activity) then if the user tell "see report on Record Manger" should open this activity. can i implement like this? – varsha jeevan Jan 02 '19 at 13:15
  • So, here is the thing. It is not going to be straight forward (I believe it is possible, but not sure till what extend) For this you need to understand how `Google Assistant` works and it's `Actions`. But I believe it is not a straight forward thing to do. – Kavin Prabhu Jan 02 '19 at 13:17
  • @varshajeevan This might help https://stackoverflow.com/questions/47479510/use-google-assistant-to-directly-talk-to-my-android-app-and-execute-a-very-simpl – Aman Rawat Jan 02 '19 at 13:31
  • Thank u all for the suggestions :) – varsha jeevan Jan 09 '19 at 07:15

2 Answers2

0

I got the answer and would like to share here,
First, do the following step,
1. add action android:name="com.google.android.gms.actions.SEARCH_ACTION" />inside the activity tag and should specify an activity label.
2. add the java code inside the activity java class:
String query = "";
if (getIntent().getAction() != null && getIntent().getAction().equals("com.google.android.gms.actions.SEARCH_ACTION")) {
query = getIntent().getStringExtra(SearchManager.QUERY);
}

varsha jeevan
  • 49
  • 1
  • 11
-2

After my searches, I can say that there is no way to do this. Your answer doesn't fit your question. Voice trigger SEARCH_ACTION is a search for "some stuff" in/on "Application"

  • sorry, my question is how to open a specified activity inside my android application through google assistant. So I didn't get any idea how to set my app to searchable. so I searched certain ways finally I got the solution – varsha jeevan Jun 05 '19 at 16:17