Sending message through WhatsApp By intent

后端 未结 2 1542
时光取名叫无心
时光取名叫无心 2020-12-03 04:05

How I can send massage from my app to Special number in whatsapp , I know this code to share massage to group or contact on whatsapp

Intent waIntent = new In         


        
相关标签:
2条回答
  • 2020-12-03 04:28

    this is a Solution :

    private void openWhatsApp(String id) {
    
    Cursor c = getSherlockActivity().getContentResolver()
                .query(ContactsContract.Data.CONTENT_URI,
                      new String[] { ContactsContract.Contacts.Data._ID },  
                      ContactsContract.Data.DATA1 + "=?",
                      new String[] { id }, 
                      null);
    
    c.moveToFirst();
    Intent i = new Intent(Intent.ACTION_VIEW, 
                  Uri.parse(
                       "content://com.android.contacts/data/" +           
                        c.getString(0)));
    
    startActivity(i);
    c.close();
    }
    

    Where id is what's app uri like 966123456789@s.whatsapp.net

    0 讨论(0)
  • 2020-12-03 04:33

    you can use this code for sending data to perticuler a number

    void openWhatsappContact(String number) {
    Uri uri = Uri.parse("smsto:" + number);
    Intent i = new Intent(Intent.ACTION_SENDTO, uri);
    i.setPackage("com.whatsapp");  
    startActivity(Intent.createChooser(i, ""));}
    

    thats realy works for me enjoy your code:)

    0 讨论(0)
提交回复
热议问题