Whatsapp意图不在联系人中的特定号码

时间:2016-07-20 11:25:01

标签: android android-intent whatsapp

我看到很多关于whatapp意图的帖子,但找不到这个问题的工作答案;

我希望Whatsapp能够将消息发送到给定的号码。这个数字不会改变。我不需要在那里留言。但是,我需要一个工作示例,即使此号码不在设备的联系人中。

似乎这是不可能的,但有没有办法以编程方式添加联系人?

由于

1 个答案:

答案 0 :(得分:2)

很抱歉迟到的回复。我想你的问题现在必须解决。您可以尝试使用以下代码打开未保存号码的对话:

private void openWhatsApp(String number) {
        try {
            number = number.replace(" ", "").replace("+", "");

            Intent sendIntent = new Intent("android.intent.action.MAIN");
            sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.Conversation"));
            sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(number)+"@s.whatsapp.net");
            context.startActivity(sendIntent);

        } catch(Exception e) {
            Log.e(TAG, "ERROR_OPEN_MESSANGER"+e.toString());
        }
    }