Android Question [SOLVED] Viber or WhatsApp contacts

Status
Not open for further replies.

makis_best

Well-Known Member
Licensed User
Longtime User
Hi.

Is there any way to find out from my phone contacts who has Viber or WhatsApp application?
If I open one contact in my contact list I can see there if that person has Viber or WhatsApp.
Can I get that information into my application?

Thank you.
 

JohnC

Expert
Licensed User
Longtime User
When you say "I open one contact in my contact list", what app are you "opening" to see your contact list?

Is it your built-in "contacts" app on your phone that you are using, or are you opening viber, and it's viber that lists your contacts that also have viber installed, etc?

The reason why I am asking is that Viber (and other such apps) probably upload your entire contact list to their servers so their servers can see if anyone in your contact list also has viber installed and if so, it will indicate this in "vibers" contact list (and not in the device's default contact app).

Otherwise, I would be hard-pressed to figure out how viber/whatsapp can modify the built-in contacts app's listing to show which contacts have viber/whatsapp.
 
Last edited:
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
When you say "I open one contact in my contact list", what app are you "opening" to see your contact list?

Is it your built-in "contacts" app on your phone that you are using, or are you opening viber, and it's viber that lists your contacts that also have viber installed, etc?

I open the built-in contacts application of my phone.
As I scroll down into the contact I can see if that contact has Viber or WhatsApp.
From there I can do direct call or video call or just a message.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
How does the default contact app indicate which contacts have viber/whats app? Does it attach a special icon to the specific contacts?

The only thing I can think of is that viber/whatsapp are modifying the contact's database/profile in some way.

This lib will help you access the data of a contact and maybe you can see how a contact is being marked as having viber/whatsapp:

 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Just curious..... is the contact's photo modified with some graphic to indicate that they have viber/whatsapp?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
So, how does the default contacts app indicate which contacts have viber/whatsapp? Does it use an Icon?
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
When you open one contact and scroll down inside contact you can see.
You must have the apps installed.
1.jpg
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
here a optimized version.
Lists only accounts which uses Whatsapp

B4X:
'Examplecall
GetAllContacts("WhatsApp")
''
Sub GetAllContacts(source As String)
    Dim projection() As String = Array As String(rawcon.CONTACT_ID,rawcon.ACCOUNT_NAME,rawcon.ACCOUNT_TYPE,rawcon.ACCOUNT_TYPE_AND_DATA_SET,rawcon.DISPLAY_NAME,rawcon.DISPLAY_NAME_ALTERNATIVE,rawcon.DISPLAY_NAME_PRIMARY,rawcon.DISPLAY_NAME_SOURCE)
    Dim selectionArgs() As String = Array As String(source)
    Dim selection As String = $"${rawcon.ACCOUNT_NAME} = ?"$
    cr.QueryAsync(rawcon.CONTENT_URI,projection, selection,selectionArgs,rawcon.ACCOUNT_NAME&" ASC")
    wait for CR_QueryCompleted(Success As Boolean, Crsr As Cursor)
    Log($"QueryCompleted(${Success})"$)
    If LastException.IsInitialized Then
        Log(LastException)
    End If
    If Crsr.IsInitialized Then
        If Crsr.RowCount > 0 Then
            Dim Cursor As Cursor
            Cursor = Crsr
            For i = 0 To Cursor.RowCount - 1
                Cursor.Position = i
                'calcon.ACCOUNT_TYPE,calcon.OWNER_ACCOUNT)
                Log($"CR --------------------------------------"$)
                Log(Cursor.GetString(rawcon.CONTACT_ID)) ' You can use the constants you used for the projection. But remember: only the ones you defined in the projection are available in the Result.
                Log(Cursor.GetString(rawcon.ACCOUNT_NAME))
                Log(Cursor.GetString(rawcon.ACCOUNT_TYPE))
                Log(Cursor.GetString(rawcon.DISPLAY_NAME))
                Log(Cursor.GetString(rawcon.DISPLAY_NAME_ALTERNATIVE))
                Log(Cursor.GetString(rawcon.DISPLAY_NAME_SOURCE))
                'Log(Cursor.GetString(rawcon.DATA4))
                'Log(Cursor.GetString(rawcon.DATA5))
            Next
            Cursor.Close
        Else
            ' No rows
        End If
    Else
        '
    End If
   
End Sub
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
here a optimized version.
Lists only accounts which uses Whatsapp

So it looks like "viber" and "whatsapp" are just different "phone books" (accounts)?

I was thinking that there was just the one contact list (phonebook) and somehow each contact was flagged as a user of viber and/or whats app.

But it now makes sense that each app would create it's own phonebook/account and the default contacts app displays all the phonebooks/accounts.

So, this would mean that there could be duplicates of contact names if a contact is in multiple books/accounts.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
So it looks like "viber" and "whatsapp" are just different "phone books" (accounts)?

Based on
i just checked the raw contact values and found what he is searching.

Table 1. Important raw contact columns.



Column nameUseNotes
ACCOUNT_NAME The account name for the account type that's the source of this raw contact. For example, the account name of a Google account is one of the device owner's Gmail addresses. See the next entry for ACCOUNT_TYPE for more information. The format of this name is specific to its account type. It is not necessarily an email address.
ACCOUNT_TYPE The account type that's the source of this raw contact. For example, the account type of a Google account is com.google. Always qualify your account type with a domain identifier for a domain you own or control. This will ensure that your account type is unique. An account type that offers contacts data usually has an associated sync adapter that synchronizes with the Contacts Provider.

Whatsapp accounts do have a ACCOUNT_NAME set to "WhatsApp" and ACCOUNT_TYPE set to "com.whatsapp"
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I was thinking that there was just the one contact list (phonebook) and somehow each contact was flagged as a user of viber and/or whats app.

This Code does lists all Contacts from any "Phonebook"....
I started using this code to see if any of the Contacts shows anything regarding Whatsapp as i am using Whatsapp and know there are contacts using it too.

B4X:
Sub GetAllContacts()
    Dim projection() As String = Array As String(rawcon.CONTACT_ID,rawcon.ACCOUNT_NAME,rawcon.ACCOUNT_TYPE,rawcon.ACCOUNT_TYPE_AND_DATA_SET,rawcon.DISPLAY_NAME,rawcon.DISPLAY_NAME_ALTERNATIVE,rawcon.DISPLAY_NAME_PRIMARY,rawcon.DISPLAY_NAME_SOURCE)
    Dim selectionArgs() As String = Array As String(0)
    Dim selection As String = $"${rawcon.CONTACT_ID} > ?"$ ' ALL Contacts with CONTACT_ID > 0
    cr.QueryAsync(rawcon.CONTENT_URI,projection, selection,selectionArgs,rawcon.ACCOUNT_NAME&" ASC")
    wait for CR_QueryCompleted(Success As Boolean, Crsr As Cursor)
    Log($"QueryCompleted(${Success})"$)
    If LastException.IsInitialized Then
        Log(LastException)
    End If
    If Crsr.IsInitialized Then
        If Crsr.RowCount > 0 Then
            Dim Cursor As Cursor
            Cursor = Crsr
            For i = 0 To Cursor.RowCount - 1
                Cursor.Position = i
                'calcon.ACCOUNT_TYPE,calcon.OWNER_ACCOUNT)
                Log($"CR --------------------------------------"$)
                Log(Cursor.GetString(rawcon.CONTACT_ID)) ' You can use the constants you used for the projection. But remember: only the ones you defined in the projection are available in the Result.
                Log(Cursor.GetString(rawcon.ACCOUNT_NAME))
                Log(Cursor.GetString(rawcon.ACCOUNT_TYPE))
                Log(Cursor.GetString(rawcon.DISPLAY_NAME))
                Log(Cursor.GetString(rawcon.DISPLAY_NAME_ALTERNATIVE))
                Log(Cursor.GetString(rawcon.DISPLAY_NAME_PRIMARY))
                Log(Cursor.GetString(rawcon.DISPLAY_NAME_SOURCE))
                'Log(Cursor.GetString(rawcon.DATA4))
                'Log(Cursor.GetString(rawcon.DATA5))
            Next
            Cursor.Close
        Else
            ' No rows
        End If
    Else
        '
    End If
  
End Sub

I did then see that ACCOUNT_NAME and ACCOUNT_NAME do show the information i was after...

On my Device i do have Contacts from the following Phonebooks

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
QueryCompleted(true)
CR-Result ----- ACCOUNT_NAME -------------------
WhatsApp
m.ssykor@xxxxxxxxxxxxxxxxxxxxxx
msy1912@xxxxxxxxx
primary.sim.account_name
primary.sim2.account_name
vnd.sec.contact.phone
CR-Result ----- ACCOUNT_TYPE -------------------
com.whatsapp
com.samsung.android.exchange
com.google
vnd.sec.contact.sim
vnd.sec.contact.sim2
vnd.sec.contact.phone

As i do not use Viber i can not say anything regarding Viber. But i expect there is a Phonebook like the one for Whatsapp.
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
When I looked at the screen shot @makis_best posted, that made it clear that each app (viber, whatsapp) simply creates it's own phonebook (account) and the default contact app simply displays all the phonebooks/accounts.

I should have asked for the screenshot in the beginning so it would have narrowed down to the solution much quicker.
 
Last edited:
Upvote 0

syerif

Active Member
Licensed User
Longtime User
Hi donmanfred,
Can i get mimetype too with this library, i need to read mimetype to get id, i have try your code but get error while change code with insert mimetype into projection. The id i got is diffrent between inline java and your sample code for whatsapp
 
Upvote 0
Status
Not open for further replies.
Top