want to open whatsapp to chat with a unsaved contact number in android app

后端 未结 2 2112
轻奢々
轻奢々 2021-02-06 16:40

i want to open whatsapp chat box for some number which is not saved in user mobile.

I am using below code :

Uri uri = Uri.parse(\"smsto:\" + str_Mobile         


        
2条回答
  •  半阙折子戏
    2021-02-06 17:19

    Sorry for late reply. I suppose your problem must be solved by now. You can try following code to open conversation for not saved numbers:

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

提交回复
热议问题