Access to contacts

606 views
Skip to first unread message

Raul SC

unread,
Nov 23, 2016, 6:20:23 PM11/23/16
to Tasker
Hello everyone, and apologize for my English.

I've been trying to access the phone's contact list from Tasker for several days, but I have not been able to get it.

I've come to find out that apps that access contacts, use this permission:

<Uses-permission android: name = "android.permission.READ_CONTACTS" />

But I can not figure out how to implement it in Tasker.

All you need is to dump all the contacts into a variable, to be able to work with that data.

Greetings and thank you

Miles M

unread,
Nov 23, 2016, 7:36:05 PM11/23/16
to Tasker
Hi Raul,
Although I can't help with this specific issue, I can offer AutoContacts by JoaoApps as a compensation. It does what you're suggesting, to allow individual contacts to be chosen from tasker; however, because its a plugin, an app cannot be exported using it, if this concerns you.
Best regards, Miles

Pent

unread,
Nov 24, 2016, 2:51:59 AM11/24/16
to Tasker

I've come to find out that apps that access contacts, use this permission:

<Uses-permission android: name = "android.permission.READ_CONTACTS" />


Tasker has that permission.

Pent
Message has been deleted

Raul SC

unread,
Nov 24, 2016, 4:02:50 AM11/24/16
to Tasker
Thanks Miles M, I knew that AutoContacs exists, but I want to turn my project into an application, so I try to do without the plugin.

Pent.

So is there any way to get what I have proposed?

For now the only thing I have achieved is that from a Tasker "Phone / Contacts" action has access to the default Android contacts application, but I can not deploy contact information to work on Tasker.

For example, to get Whatsapp contacts I use the following SQL code:

Acción 1: chmod 666 /data/data/com.whatsapp/databases/wa.db
Acción 2: sqlite3 /data/data/com.whatsapp/databases/wa.db "SELECT jid FROM wa_contacts WHERE display_name LIKE '%NOMBRE O VARIABLE AQUÍ%' AND is_whatsapp_user=1 LIMIT '3000';"

With this code I get a variable that contains all Whatsapp contacts, but it is necessary to have ROOT access.

I'm hoping you can perform a similar task to access your phone contacts without having to access ROOT

Greetings and thanks

Pent

unread,
Nov 24, 2016, 9:59:58 AM11/24/16
to Tasker
I don't know where the contacts DB is, but I suspect it's read-protected so you would need root
for that too.

There's an SQL query action in the next update, but it's for files only currently.

I will see if it's easily modifiable for internal DBs too.

Pent

Rich D

unread,
Nov 24, 2016, 10:30:13 AM11/24/16
to Tasker Google Groups Post


> There's an SQL query action in the next update, but it's for files only currently.
>
> I will see if it's easily modifiable for internal DBs too.

Just curious if it would be possible to modify the current Tasker phone / test phone action to get all contact info?

Pent

unread,
Nov 25, 2016, 3:26:10 AM11/25/16
to Tasker
OP: querying internal DBs via an Android content URI is definitely possible
in the next update, beta before end of next week. You will need to manually
add the READ_CONTACTS permission in order to use it in a child app however.

 

Just curious if it would be possible to modify the current Tasker phone / test phone action to get all contact info?


Yes, but there's a huge amount of info, I wouldn't want to go into all the possibilities,
the SQL query is much more flexible, if daunting for the SQL novice.

Pent

Raul SC

unread,
Nov 25, 2016, 3:49:37 AM11/25/16
to Tasker
Thank you for continuing to improve this fantastic application. A greeting.

Phil Bilton

unread,
Jan 20, 2017, 7:19:41 PM1/20/17
to Tasker
Sorry four asking this but doing a Google search just turns up posts from years ago and the search on the forum is broken.

Is this now possible to do without root? To look up contact names and numbers? I would also like to add this to my new app, as it stands, my user's have to copy and paste contact numbers.

Thanks
Phil

Pent

unread,
Jan 21, 2017, 3:21:54 AM1/21/17
to Tasker

Is this now possible to do without root? To look up contact names and numbers?


Yes.

Pent

Raph

unread,
Jan 21, 2017, 5:09:57 AM1/21/17
to Tasker

We discussed this issue recently in this forum. Tasker already has an action to obtain some other contact details if you know the phone number. Check out "Test Phone". Some of us who discovered this viewed that "Test Phone" is perhaps not the best place for that action.

Phil Bilton

unread,
Jan 21, 2017, 6:16:45 AM1/21/17
to Tasker
I did see the test phone to get a contact name and thought that was as far as we could go.

Tbh I've been busy building this project without exploring new features so I must of missed the contact threads. Now the project is just about finished I'm interested in tweaking the UI as I get feedback from testers.

Abdullah Alahdal

unread,
Jan 21, 2017, 3:06:21 PM1/21/17
to Tasker
You can access the contacts using SQL query with URI formatted

content://com.android.contacts/raw_contacts

From above you can get the contact name 'display_name' and his id 'contact_id. Then you would need another query to get phone numbers in

content://com.android.contacts/phone_lookup

However, I'm facing issues with duplicates because distinct selection does not work. Maybe Pent can help.


22.49.18/Variables doreplresult: |display_name like '%Alahdal%'| -> |display_name like '%Alahdal%'|
22.49.18/E SQL Query: %name -> %name
22.49.18/E SQL Query: URI cursor exception: java.lang.IllegalArgumentException: Invalid column distinct contact_id
22.49.18/E SQL Query: no cursor for query 'display_name like '%Alahdal%''
22.49.18/E result: stop task (error)
22.49.18/Variables doreplresult: |%name| -> |%name|
22.49.18/E Error: 1
22.49.18/MacroEdit action finished exeID 1 action no 1 code 667 status: Err next 1

Phil Bilton

unread,
Jan 21, 2017, 4:30:36 PM1/21/17
to Tasker
I'm struggling with getting the numbers, I'm unsure of the columns. This is the first time I've used this.

Abdullah Alahdal

unread,
Jan 21, 2017, 11:35:43 PM1/21/17
to Tasker
I'm struggling with getting the numbers, I'm unsure of the columns. This is the first time I've used this.

You can get the number by

1. Get the contact ID from content://com.android.contacts/raw_contacts
2. Get the number using the id from content://com.android.contacts/phone_lookup 

Phil Bilton

unread,
Jan 22, 2017, 4:54:30 AM1/22/17
to Tasker
Thanks for your help, but I'm getting the error illegalArgumentExecption so I'm assuming I'm inputting it wrong.
For the contract I'd results is a set of numbers, first result returned 18, the tenth result returned 314.
I've tried putting %contact_id10 into the second SQL query in the column and then selection sections but both cause the error.

Abdullah Alahdal

unread,
Jan 22, 2017, 5:57:21 AM1/22/17
to Tasker
I've tried putting %contact_id10 into the second SQL query in the column and then selection sections but both cause the error.

Share your task description. By holding to select the Task then export description to clipboard. you need to disable beginner mode.

Phil Bilton

unread,
Jan 22, 2017, 6:57:52 AM1/22/17
to Tasker
It's just a test task to get this figured out. No doubt I have it all wrong as I mentioned before I've never touched SQL

Test (251)
A1: SQL Query [ Mode:URI Formatted File:content://com.android.contacts/raw_contacts Table: Columns:contact_id Query: Selection Parameters: Order By: Output Column Divider: Variable Array:%contact_id Use Root:Off ]
A2: Flash [ Text:%contact_id10 Long:Off ]
A3: SQL Query [ Mode:URI Formatted File:content://com.android.contacts/phone_lookup Table: Columns: Query:%contact_id10 Selection Parameters: Order By: Output Column Divider: Variable Array:%nunber Use Root:Off ]

Abdullah Alahdal

unread,
Jan 22, 2017, 9:43:10 AM1/22/17
to Tasker
in A3, you need to identify the column in the selection (Query). 

I am also trying to figure out which column should we take 

Phil Bilton

unread,
Jan 22, 2017, 11:53:13 AM1/22/17
to Tasker
Ah ok, that makes sense why it's throwing the error.

Raph

unread,
Jan 22, 2017, 1:50:59 PM1/22/17
to Tasker

I have explored this quite a bit and it works. My biggest challenge remains how to get custom fields created in Google Contacts. Those fields are not in contacts, raw_contacts or in phone_lookup. My Google search has not pointed to anywhere the location of the custom fields is.

Reply all
Reply to author
Forward
0 new messages