1

I'm​ developing a small messaging app on my own and I was wondering if there is a possibility to allow the user to send messages using the Google Assistant. (Like WhatsApp and Google Allo)

Which API could I use to archive this?

chrstnwhlrt
  • 331
  • 1
  • 4
  • 18
  • Hey mate are you talking of https://developers.google.com/actions/ – Ayush Bansal May 14 '17 at 13:02
  • 2 libs/sample apps to look over .... https://github.com/grpc/grpc-java/tree/master/examples/android/helloworld/app https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/speech – Robert Rowntree May 14 '17 at 14:54
  • @AyushBansal do I need to create a custom action? To clearify: If the user has the messenger installed, one could send a message by just saying "Ok Google, send a message using *** to ***". – chrstnwhlrt May 14 '17 at 17:02
  • Am trying , i will let u know if I am able to code it properly . – Ayush Bansal May 14 '17 at 17:30
  • @chris go through this video https://www.youtube.com/watch?time_continue=91&v=PS1FbB5qWEI – Ayush Bansal May 14 '17 at 17:35
  • @AyushBansal Okay this helps to get the user a way of searching within an app. Is there a way for message interaction? WhatsApp has this dialogue way with Google now which allows sending messages even without starting WhatsApp. – chrstnwhlrt May 15 '17 at 10:16
  • yeah just tried that feature it's awesome man . let me try . it will take sme time though (2-3days). – Ayush Bansal May 16 '17 at 04:44

2 Answers2

0

Before going through the code please go through this links answer along with comments .

So as mentioned there are two types of actions that can be registered 1) Custom Action 2) System Action Here app has been registered with TAKE A NOTE action(a system generated action). This is registered in the Manifest to let the system know that it accepts the intents which are related to taking a note.(Hope i have not over explained it)

=== Code ===

Manifest.xml

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <action android:name="com.google.android.gms.actions.CREATE_NOTE" />
        <category android:name="android.intent.category.VOICE"/>
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain"/>
    </intent-filter>

MainActivity.java

public class VoiceAction extends AppCompatActivity {

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_voice_action);
         Intent t = getIntent();
         String s = t.getStringExtra(Intent.EXTRA_TEXT);
         System.out.println("====" + s);

     } }

This how i tested it

Ok Google -> take a note -> google asks me choose an app -> choose the app to be tested -> give a note or a text to it -> see your log (text you said is printed there).

I will edit the answer to meet your need exactly in some time . Hope this helps

Community
  • 1
  • 1
Ayush Bansal
  • 702
  • 1
  • 7
  • 17
0

I saw something in the WhatsApp manifest :

Apparently they are using this action : com.google.android.voicesearch.SEND_MESSAGE_TO_CONTACTS

No trace of that in any docs... Coincidence, I think not...

https://github.com/GigaDroid/Decompiled-Whatsapp/blob/master/AndroidManifest.xml

Lowdev
  • 1
  • 1