我正在尝试向特定号码发送whatsapp消息,而无需保存该联系人。
这是我的代码
void test()
{
__asm
{
mov eax, [ebp+4]
add eax, 0x12
mov [ebp+4], eax
}
}
以及我从
获得的消息答案 0 :(得分:4)
在这里试试。这对我有帮助
private void openWhatsApp() {
String smsNumber = "+26377*********";
boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp");
if (isWhatsappInstalled) {
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(smsNumber) + "@s.whatsapp.net");//phone number without "+" prefix
startActivity(sendIntent);
} else {
Uri uri = Uri.parse("market://details?id=com.whatsapp");
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
Toast.makeText(this, "WhatsApp not Installed",
Toast.LENGTH_SHORT).show();
startActivity(goToMarket);
}
}
private boolean whatsappInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
答案 1 :(得分:0)
您可以使用此代码:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(smsNumber) + "@s.whatsapp.net");//phone number without "+" prefix
startActivity(sendIntent);
它会帮助你
答案 2 :(得分:0)
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.Conversation"));
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("**91**"+smsnumber) + "@s.whatsapp.net");//phone number without "+" prefix
context.startActivity(sendIntent);
答案 3 :(得分:0)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
if (requestCode == PICK_IMAGE_CODE) {
if (data != null) {
val image = data.data
val number = "9163********"
val whatsappIntent = Intent(Intent.ACTION_SEND)
whatsappIntent.setPackage("com.whatsapp")
whatsappIntent.setType("text/plain")
whatsappIntent.putExtra(
Intent.EXTRA_TEXT,
"I am sending the image for testing"
)
whatsappIntent.putExtra(Intent.EXTRA_STREAM, image)
whatsappIntent.setType("image/*")
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
whatsappIntent.putExtra(
"jid",
PhoneNumberUtils.stripSeparators(number) + "@s.whatsapp.net"
) //phone number without "+" prefix
startActivity(whatsappIntent)
}
}
}
}
在清单中:(在应用程序标签下方)(用于 android 11 支持)
<queries>
<package android:name="com.whatsapp" />
<package android:name="com.whatsapp.w4b" />
</queries>
它会帮助你,对我来说效果很好
使用此功能后,您可以从存储中选择文件并将其发送到带有一些文本的whatsapp上未保存的号码