Android Question WhatsApp Intent

MarcoRome

Expert
Licensed User
Longtime User
Hi all.

If you send message with intent / WhatsApp write this code:
B4X:
Dim i As Intent
i.Initialize(i.ACTION_SEND,"")
i.SetType("text/plain")
i.SetComponent("com.whatsapp/.ContactPicker")
i.PutExtra("android.intent.extra.TEXT","HELLO")
StartActivity(i)

and all work. But if i want send to specific contact i found this code:

B4X:
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", smsText);
i.setPackage("com.whatsapp");
startActivity(i);

this is website: http://stackoverflow.com/questions/19081654/send-text-to-specific-contact-whatsapp

i Try in this mode but dont work, this is code:

B4X:
    Dim i As Intent
    Dim smsNumber As String = "+393889XXXXXX"
    Dim numero As Uri
numero.Parse("smsto:" & smsNumber)
i.Initialize(i.ACTION_SEND, numero)
i.SetType("text/plain")
i.SetComponent("com.whatsapp")
i.PutExtra("android.intent.extra.TEXT","HELLO")
StartActivity(i)

i try also this:

B4X:
.....
numero.Parse("smsto:" & smsNumber)
i.Initialize(i.ACTION_SEND, numero)
i.SetType("text/plain")
Dim jo As JavaObject = i
jo.RunMethod("setPackage", Array As Object("com.whatsapp"))
i.PutExtra("android.intent.extra.TEXT","HELLO")
StartActivity(i)

Any idea ??
Thank you in advance
 
Last edited:

Humberto

Active Member
Licensed User
Longtime User
Inakigarm

Could you send the message to a specific contact?

I can send a message but you have to choose the contact

B4X:
Intent1.Initialize(Intent1.ACTION_VIEW ,"")
   
    Intent1.SetType("text/plain")
   
    Intent1.PutExtra("android.intent.extra.TEXT", "Message to send" )

    Intent1.SetComponent("com.whatsapp/.ContactPicker") 
    StartActivity(Intent1)

When I use the Erel tip doesn´t work, the ais a message bellow

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=(StringUri) smsto:+5513997568917 typ=text/plain flg=0x20001 pkg=com.whatsapp (has clip) (has extras) }


at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1569)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420)
at android.app.Activity.startActivityForResult(Activity.java:3446)
at android.app.Activity.startActivityForResult(Activity.java:3407)
at android.app.Activity.startActivity(Activity.java:3617)
at android.app.Activity.startActivity(Activity.java:3585)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:686)
at b4a.example.main._bt_send_click(main.java:369)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)


at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17267)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=(StringUri) smsto:+5513997568917 typ=text/plain flg=0x20001 pkg=com.whatsapp (has clip) (has extras) }
 
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
Inakigarm

Could you send the message to a specific contact?

I can send a message but you have to choose the contact

B4X:
Intent1.Initialize(Intent1.ACTION_VIEW ,"")
  
    Intent1.SetType("text/plain")
  
    Intent1.PutExtra("android.intent.extra.TEXT", "Message to send" )

    Intent1.SetComponent("com.whatsapp/.ContactPicker")
    StartActivity(Intent1)

When I use the Erel tip doesn´t work, the ais a message bellow

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=(StringUri) smsto:+5513997568917 typ=text/plain flg=0x20001 pkg=com.whatsapp (has clip) (has extras) }


at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1569)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420)
at android.app.Activity.startActivityForResult(Activity.java:3446)
at android.app.Activity.startActivityForResult(Activity.java:3407)
at android.app.Activity.startActivity(Activity.java:3617)
at android.app.Activity.startActivity(Activity.java:3585)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:686)
at b4a.example.main._bt_send_click(main.java:369)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)


at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17267)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=(StringUri) smsto:+5513997568917 typ=text/plain flg=0x20001 pkg=com.whatsapp (has clip) (has extras) }

}Hola humberto, pudiste enviar a un contacto especifico?? llevo rato investigando pero solo logro abrir los contactos de whatsapp no he podido enviar el mensaje a un numero que yo especifique
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I could not send a message to a specific contact, the user has to choose one.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
How to send automatically like this


That video is using Whatsapp. Just say to your device 'okay google send a whatsapp message', google will respond with 'who do you want to message', you say a name, google will ask you 'whats the message', you say the message. If your device must be already be unlocked for this to work.

If you use Android Auto, then all this can be done without unlocking your phone as it's already unlocked, google will also read any response messages out to you...
 
Last edited:
Upvote 0

Oke

Member
Licensed User
Longtime User
That video is using Whatsapp. Just say to your device 'okay google send a whatsapp message', google will respond with 'who do you want to message', you say a name, google will ask you 'whats the message', you say the message. If your device must be already be unlocked for this to work.

If you use Android Auto, then all this can be done without unlocking your phone as it's already unlocked, google will also read any response messages out to you...


Thank you, Mr. Peter Simpson, can we make such an application that sends messages automatically via WhatsApp, without having to press the send button ?
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Thank you, Mr. Peter Simpson, can we make such an application that sends messages automatically via WhatsApp, without having to press the send button ?

You don't need the press sent after saying the message. A few seconds after you stop speaking, Google asks you the following question. "Do you wish to sent it or change it", just say sent it and it will send the message via what's app. I use that fuction all the some when I'm coding on my laptop and especially when I'm driving my car as I don't need to touch any screens, I just say okay Google send a WhatsApp message and it just does it. Give it a go, especially if you have the okay Google or hey Google keywords already active on your phone :cool:
 
Last edited:
Upvote 0

Oke

Member
Licensed User
Longtime User
You don't need the press sent after saying the message. A few seconds after you stop speaking, Google asks you the following question. "Do you wish to sent it or change it", just say sent it and it will send the message via what's app. I use that fuction all the some when I'm coding on my laptop and especially when I'm driving my car as I don't need to touch any screens, I just say okay Google send a WhatsApp message and it just does it. Give it a go, especially if you have the okay Google or hey Google keywords already active on your phone :cool:

well sir i understand, thank you
 
Upvote 0
Top