contacts to variable

1,057 views
Skip to first unread message

Teasüti

unread,
Jun 11, 2012, 11:56:18 AM6/11/12
to Tasker
Hi, how to assign phonebook contacts to variables?
Thanks!

Also could use the C:FAV in tasks, like send sms.

Teasüti

unread,
Jul 2, 2012, 11:43:54 AM7/2/12
to tas...@googlegroups.com
Nohow?

Wietse van Buitenen

unread,
Jul 2, 2012, 2:25:17 PM7/2/12
to tas...@googlegroups.com
there is no real way in Tasker but you could use a script to query the contacts database..
you will need to be root though..

sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db 'SELECT title FROM groups WHERE _id IN (SELECT data.data1 FROM data INNER JOIN raw_contacts ON data.raw_contact_id=raw_contacts._id WHERE data.mimetype_id IN (SELECT _id FROM mimetypes WHERE mimetype="vnd.android.cursor.item/group_membership") AND raw_contacts.display_name="Name Lastname")'

this gives back a list of groups where the contact name matches..
you could then replace the name with %CNAME to get the caller

note it takes 1 second on my SGSII and about 3 seconds on an HTC Desire..
it is tested on CM7.2 & CM9
the reason for the subquery to get the mimetype is because it didn't have the same _id on CM7.2 and CM9..

Matt R

unread,
Aug 27, 2012, 6:43:59 PM8/27/12
to tas...@googlegroups.com
TW, could you point to where to get info about how to query the contacts database in this way?  I've tried looking for explainations online but they're not very clear.  I understand the syntax mostly, but how do you determine that you want "title" from "groups" and all of the subquery information?
 
Thanks,
Matt

10amla

unread,
Aug 28, 2012, 12:40:25 AM8/28/12
to tas...@googlegroups.com
You don't need root.  I do it though SL4A with queryContent.

On Monday, July 2, 2012 11:25:17 AM UTC-7, Wietse van Buitenen wrote:

Matt R

unread,
Aug 28, 2012, 1:31:01 AM8/28/12
to tas...@googlegroups.com
Both ways would be good to have explained!

Matt

10amla

unread,
Aug 28, 2012, 3:20:13 AM8/28/12
to tas...@googlegroups.com
OK, I'll give it a go.
 
Here's the basic syntax(Python):
 
import android
droid = android.Android()
Phonenum = droid.queryContent('content://com.android.contacts/data/phones', ['data1', 'data2', 'data3'], 'data2 == 0 and data3 = "Google Voice" and display_name = "' + strSender +'"', None, None).result
 
var = droid.queryContent(URI of the contact database to query,
     [Columns to return],
     db query,
     query attributes(I've never used this),
     sort(haven't used this either))
There are 3 main databases in contacts: Contacts, RawContacts, and Data.  There's also a phone db for caller ID lookup.
I don't remember all the URI's but here's a couple: Data - 'content://com.android.contacts/data'
        Phone - 'content://com.android.contacts/data/phones'
I was looking for Nicknames and display pic URI's but there's alot in there, do some queries with differnt conditions and see what's there.

Wietse van Buitenen

unread,
Aug 28, 2012, 3:47:17 AM8/28/12
to tas...@googlegroups.com
I opened the .db file in an sqlite3 tool and built the query to my needs :)
if you see the contents it's clear which fields you need
it's possible the query isn't optimal but at least it works :)

if you only want to use it on your phone you could skip the subquery for mimetypes and just fill in a fixed value
I keep it in because I want it to work.. like always.. :)

Wietse van Buitenen

unread,
Aug 28, 2012, 3:48:17 AM8/28/12
to tas...@googlegroups.com
this is interesting!
didn't know it could be done with SL4A, will try this out some time

Michael Yeager

unread,
Sep 30, 2012, 10:27:37 AM9/30/12
to tas...@googlegroups.com
I guess I'm going to have to look into this a bit. Going to be a lot of questions as I'll be delving into completely unknown territory. Anyone up to the challenge of helping a newbie lost in the forest???

Saad Thahim

unread,
May 21, 2013, 1:48:54 AM5/21/13
to tas...@googlegroups.com
How can I write rhis script in sl4a can u give details.

Sam Raisbeck

unread,
May 27, 2013, 7:38:33 PM5/27/13
to tas...@googlegroups.com
Can you recommend a good sl4a editor for on phone scripting?
Reply all
Reply to author
Forward
0 new messages