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:::
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
    29.4 KB · Views: 189
Cookies are required to use this site. You must accept them to continue using the site. Learn more…