Android Question Create Library Whatsapp

MarcoRome

Expert
Licensed User
Longtime User
Hi all.
B4X:
public final static boolean existNumber(BA ba, String phoneNumber){
        boolean exist = false;
 
        try{
            ContentResolver contentResolver = ba.context.getContentResolver();
            Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
            if (cursor.getCount() > 0) {
                while (cursor.moveToNext()) {
                    String contact_id = cursor.getString(cursor.getColumnIndex( ContactsContract.Contacts._ID ));
                    int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex( ContactsContract.Contacts.HAS_PHONE_NUMBER )));
                    if (hasPhoneNumber > 0) {
                        Cursor phoneCursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { contact_id }, null);
                        while (phoneCursor.moveToNext()) {
                            String phoneNumberContact = phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                            if(phoneNumber.equals(phoneNumberContact)){
                                exist = true;
                                phoneCursor.close();
                                cursor.close();
                                return exist;
                            }
                        }
                        phoneCursor.close();
                    }
                }
            }
            cursor.close();
        }catch(Exception e){
            exist = false;
            if(DEBUG) Log.e("Exception", e.toString());
        }
 
        return exist;
    }

return False... also if number exit.

Any idea ??




Thank you all
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Hi MarcoRome,
did you port it to b4a?
In attachment you have library B4A already compiled ( whatssapp_lbrary.zip ) and start example but as already write... existPhoneNumber dont work...another function
shareMediaWithContact, lunchmarket, etc. i have yet to try them.
 
Upvote 0
Top