Android Question whatsapp cannot send

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
i believed that whatsapp can not send,but now all what i need is to open whatsapp chat window for specified contact and put the pre text on it,
i tried the following code but it opens the chat window for specified contact without the pre text.
B4X:
Uri uri = Uri.parse("smsto:+xxxxxxxx");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
i.putExtra("sms_body", "fffff");
i.setPackage("com.whatsapp"); 
startActivity(i);
.
i modified that and i tried to adding
B4X:
i.setType("text/plain");
B4X:
Uri uri = Uri.parse("smsto:+xxxxxxxx");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setType("text/plain");
i.setPackage("com.whatsapp");           // so that only Whatsapp reacts and not the chooser
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
startActivity(i);

but it gives the error showen in image bellow
i removed
B4X:
i.setType("text/plain");
and i added as follow:

B4X:
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse("content://com.android.contacts/data/+xxxxxxxx" ));
i.setPackage("com.whatsapp");           // so that only Whatsapp reacts and not the chooser
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
startActivity(i);

but it gives the same error in the image
and logs error as follow:::
LogCat connected to: eb1fef96
--------- beginning of system--------- beginning of main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Resume **
main_button1_down (java line: 347)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at b4a.example.main._button1_down(main.java:347)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA$2.run(BA.java:299)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO dat=content://com.android.contacts/data/+967774159613 pkg=com.whatsapp (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1801)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1499)
at android.app.Activity.startActivityForResult(Activity.java:3942)
at android.app.Activity.startActivityForResult(Activity.java:3889)
at android.app.Activity.startActivity(Activity.java:4213)
at android.app.Activity.startActivity(Activity.java:4181)
at b4a.example.main.wts(main.java:396)
... 16 more
java.lang.reflect.InvocationTargetException
the whole code is::
B4X:
Sub Process_Globals
    Private nativeMe As JavaObject
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("x")
    If FirstTime Then
    nativeMe.InitializeContext
    End If
    'nativeMe.runMethod("wts",Array(nativeMe))
End Sub

#If JAVA
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.content.DialogInterface;
import android.app.Activity;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.content.pm.PackageManager;
public void wts()
{
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse("content://com.android.contacts/data/+xxxxxxxx" ));
i.setPackage("com.whatsapp");           // so that only Whatsapp reacts and not the chooser
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
startActivity(i);
#end if

Sub Button1_Down
nativeMe.runMethod("wts",Null)
End Sub
,
i'll be thankful for any help.
 

Attachments

  • 12596284_1030300677008179_1265561177_n.jpg
    12596284_1030300677008179_1265561177_n.jpg
    29.4 KB · Views: 187
Top