首页 文章

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

提问于
浏览
2

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

我希望Whatsapp能够将消息发送到给定的号码 . 这个数字不会改变 . 我不需要在那里留言 . 但是,我需要一个有效的例子 even if this number isn't in the contacts of the device.

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

谢谢

1 回答

  • 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());
            }
        }
    

相关问题