如何在Android上获取Whatsapp联系人的姓名

时间:2018-10-30 14:36:10

标签: android contacts whatsapp

我的代码在这里我想获取联系人姓名。如何获取whatsapp联系人姓名。

String adress = intent.getStringExtra("contact");
                String phone = adress.split("@")[0];
                String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                        ContactsContract.CommonDataKinds.Phone.NUMBER,
                        ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER };
                ContentResolver cr=getContentResolver();
                String selection = ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER + " = " + phone;
                Cursor c = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, selection, null, null);
                int contactnameColumn=c.getColumnIndex(ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY);
                if (c != null && c.moveToFirst()) {
                    Log.e(TAG, "name: "+ c.getString(0));
                    Toast.makeText(getApplicationContext(),"name:"+c.getString(0),Toast.LENGTH_SHORT).show()

0 个答案:

没有答案