Android Question WhatsApp msg not sending

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi,

I am trying to send a pdf in files folder thru WhatsApp as below but it shows "No app can perform this action" .

In starter I have only declared
Dim Provider as FileProvider

In Manifest
B4X:
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)

CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)

In btnSend_Click
B4X:
Sub SendPDF(sNumber As String)
    Starter.provider.Initialize
    File.Copy(File.dirassets,"document.pdf",Starter.Provider.SharedFolder,"document.pdf")
    Dim sendIntent As Intent
    sendIntent.Initialize(sendIntent.ACTION_MAIN,"")
    sendIntent.Action=sendIntent.ACTION_SEND
    sendIntent.SetPackage("com.whatsapp")
    sendIntent.SetComponent("android/com.android.internal.app.ResolverActivity")
    sendIntent.putExtra("jid", sNumber & "@s.whatsapp.net")
   
    sendIntent.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri("document.pdf"))
    sendIntent.PutExtra("android.intent.extra.TEXT","")
    sendIntent.SetType("application/pdf")
    sendIntent.Flags=1
    StartActivity(sendIntent)
End Sub

I think i am missing something. Erel has mentioned files-path=File.DirInternal. I am not using that folder.

Can someone pls give some clue.

Thanks
Juzer
 

Juzer Hussain

Active Member
Licensed User
Longtime User
Thanks Erel,

No I am not able to send plain text also.

B4X:
Dim sendIntent As Intent
    sendIntent.Initialize(sendIntent.ACTION_MAIN,"")
    sendIntent.Action=sendIntent.ACTION_SEND
    sendIntent.SetPackage("com.whatsapp")
    sendIntent.putExtra("jid", number & "@s.whatsapp.net")
    sendIntent.PutExtra("android.intent.extra.TEXT","Trial Msg")
    sendIntent.SetType("text/plain")
    StartActivity(sendIntent)

Shows error as below-:

Error occurred on line: 59 (frmWASender)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/plain flg=0x20001 pkg=com.whatsapp clip={text/plain T:Trial Msg} (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2071)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1717)
at android.app.Activity.startActivityForResult(Activity.java:5250)
at android.app.Activity.startActivityForResult(Activity.java:5208)
at android.app.Activity.startActivity(Activity.java:5579)
at android.app.Activity.startActivity(Activity.java:5547)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:857)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
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.debug.Debug.delegate(Debug.java:262)
at com.CustomerLoyalty.frmwasender._sendpdf(frmwasender.java:425)
at com.CustomerLoyalty.frmwasender._btnsendpdf_click(frmwasender.java:417)
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:351)
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)

I checked in forum the set component is used everywhere like that only.

B4X:
    Dim Intent1 As Intent
    Intent1.Initialize(Intent1.ACTION_SEND, $"https://api.whatsapp.com/send?phone=${"91123456789"}&text=${"Hello"}"$)
    StartActivity(Intent1)

This code opens Whatsapp with msg. Just checked I don't need this.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
se this

try also
B4X:
<manifest package="com.example.app">
    <queries>
        <package android:name="com.whatsapp"/>
        <package android:name="com.whatsapp.w4b"/>
    </queries>
  ...
</manifest>
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
se this

try also
B4X:
<manifest package="com.example.app">
    <queries>
        <package android:name="com.whatsapp"/>
        <package android:name="com.whatsapp.w4b"/>
    </queries>
  ...
</manifest>
Hi Star-Dust,

Where to add this?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I think in to maifest
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
Thanks Erel,

No I am not able to send plain text also.

B4X:
Dim sendIntent As Intent
    sendIntent.Initialize(sendIntent.ACTION_MAIN,"")
    sendIntent.Action=sendIntent.ACTION_SEND
    sendIntent.SetPackage("com.whatsapp")
    sendIntent.putExtra("jid", number & "@s.whatsapp.net")
    sendIntent.PutExtra("android.intent.extra.TEXT","Trial Msg")
    sendIntent.SetType("text/plain")
    StartActivity(sendIntent)

Shows error as below-:

Error occurred on line: 59 (frmWASender)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/plain flg=0x20001 pkg=com.whatsapp clip={text/plain T:Trial Msg} (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2071)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1717)
at android.app.Activity.startActivityForResult(Activity.java:5250)
at android.app.Activity.startActivityForResult(Activity.java:5208)
at android.app.Activity.startActivity(Activity.java:5579)
at android.app.Activity.startActivity(Activity.java:5547)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:857)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
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.debug.Debug.delegate(Debug.java:262)
at com.CustomerLoyalty.frmwasender._sendpdf(frmwasender.java:425)
at com.CustomerLoyalty.frmwasender._btnsendpdf_click(frmwasender.java:417)
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:351)
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)

I checked in forum the set component is used everywhere like that only.

B4X:
    Dim Intent1 As Intent
    Intent1.Initialize(Intent1.ACTION_SEND, $"https://api.whatsapp.com/send?phone=${"91123456789"}&text=${"Hello"}"$)
    StartActivity(Intent1)

This code opens Whatsapp with msg. Just checked I don't need this.
Erel, Sorry the problem was i use Whatsapp Business for it package name is "com.whatsapp.w4b". Now WhatsApp is opening with PDF.
We still need to click send button to actually send it. Is there any way to automate it.
 
Upvote 0
Top