Android Question Interacting With WhatsApp [Solved]

RichardN

Well-Known Member
Licensed User
Longtime User
I have an application that integrates Text-To-Speech with WhatsApp. Previously the App could gather text from the user and invoke WhatsApp allowing the user to select an addressee from the WhatsApp address-book using 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",MyText)
    StartActivity(i)

Now the exception below occurs at the 'StartActivity' line. There are other solutions on the forum initialising the intent using a Java Object but no joy with that either. Is it still possible to invoke WhatsApp to send a plain text message to a selected addressee?

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (main) Resume **
Error occurred on line: 122 (Main)
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.whatsapp/com.whatsapp.ContactPicker}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2098)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1747)
at android.app.Activity.startActivityForResult(Activity.java:5465)
at android.app.Activity.startActivityForResult(Activity.java:5423)
at android.app.Activity.startActivity(Activity.java:5809)
at android.app.Activity.startActivity(Activity.java:5762)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:857)
at com.waterline.whatsappdictate.main._btnwhatsapp_click(main.java:544)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
 
Last edited:

RichardN

Well-Known Member
Licensed User
Longtime User
Using the example from https://www.b4x.com/android/forum/t...ssage-to-specific-phone-number.84398/#content

Removing the 'phone' variable from the URI allows the user to select one or more addressees from the WhatsApp 'Send To' dialog before the text is dispatched. Test device is with TargetSDK=30 on a Samsung S22 Ultra with Android 12.

B4X:
Sub btnWhatsApp_Click
    
    Dim Intent1 As Intent
 
    Intent1.Initialize(Intent1.ACTION_VIEW, $"https://api.whatsapp.com/send?text=${TextToSend}"$)
    Intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
    StartActivity(Intent1)
    
End Sub
 
Upvote 0
Top