Android Question Send PDF with Whatsapp

menneaduplo

Member
Licensed User
Longtime User
Hi All,
I need to send a PDF via whatsapp.
The code below has stopped working. I don't know exactly when.
I don't think it depends on B4a 11.50. Maybe Whatsapp has changed something?
Can anyone help me.


pdfWhataspp:
    File.Copy(File.DirDefaultExternal,"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.SetComponent("com.whatsapp/.ContactPicker")
    sendIntent.putExtra("jid", PhoneNumber & "@s.whatsapp.net")
    
    sendIntent.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri("documento.pdf"))
    sendIntent.PutExtra("android.intent.extra.TEXT","Si allega documento :")
    sendIntent.SetType("application/pdf")
    StartActivity(sendIntent)

There is the following exception
Thanks in advance.

eccezione:
StartActivity(sendIntent)
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:2078)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727)
    at android.app.Activity.startActivityForResult(Activity.java:5377)
    at android.app.Activity.startActivityForResult(Activity.java:5335)
    at android.app.Activity.startActivity(Activity.java:5721)
    at android.app.Activity.startActivity(Activity.java:5674)
    at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:857)
    at b4a.example.main._buttonsend_click(main.java:485)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    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)
    at android.view.View.performClick(View.java:8160)
    at android.widget.TextView.performClick(TextView.java:16222)
    at android.view.View.performClickInternal(View.java:8137)
    at android.view.View.access$3700(View.java:888)
    at android.view.View$PerformClick.run(View.java:30236)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.ActivityThread.main(ActivityThread.java:8653)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
 

asales

Expert
Licensed User
Longtime User
I use this code:
B4X:
Dim i As Intent
i.Initialize(i.ACTION_SEND, "")
i.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri("file.pdf"))
i.SetType("text/plain") 'it is not related to the file itself.
StartActivity(i)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Also note to use Fileprovider in your app. Above code is based on fileprovider.

 
Upvote 1

menneaduplo

Member
Licensed User
Longtime User
Solved,
it was enough to comment one line. Below the working code.
Thanks

code:
    File.Copy(File.DirDefaultExternal,"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.SetComponent("com.whatsapp/.ContactPicker")
    sendIntent.putExtra("jid", PhoneNumber & "@s.whatsapp.net")
    
    sendIntent.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri("documento.pdf"))
    sendIntent.PutExtra("android.intent.extra.TEXT","Si allega documento :")
    sendIntent.SetType("application/pdf")
    StartActivity(sendIntent)
 
Upvote 0
Top