Trying to get the mobile number from contact URI

1,980 views
Skip to first unread message

aboveth...@gmail.com

unread,
Feb 24, 2021, 10:25:23 PM2/24/21
to Automate

I've been trying to figure this out for several hours now, I've gone through the threads but can't seem to get it to work.

I'm trying to send an SMS to a selected contact.

After selecting a contact through the pick contact block I save the contact URI to a variable called ContactSelected. I notice when selecting a contact, you only have the primary number available, it doesn't give you the option of choosing which number to use.

I'm then trying to use a query content block to get the mobile number of the selected contact, but I can only seem to get the primary phone number.

Can anyone help with this.

Thanks

Henrik "The Developer" Lindqvist

unread,
Feb 25, 2021, 2:31:52 AM2/25/21
to Automate
Try Content query block...
  • Content URI: content://com.android.contracts/data
  • Columns: data1
  • Where clause: contact_id={split(pickedContactUri, "/")[-1]} and mimetype='vnd.android.cursor.item/phone_v2' and data2=2
  • Result type: Concatenated rows

aboveth...@gmail.com

unread,
Feb 25, 2021, 9:45:51 AM2/25/21
to Automate
Keeps saying "java.lang.NullPointerException: Attemp to invoke interface method 'void android.database.Cursor.close()' on a null object reference"

Perhaps it has something to do with the "vnd.android.cursor.item/phone_v2"?

When I load items in com.android.contact/groups and use distinct(split(join(result, "\n"), "\n")) I have 4 accounts...

+1 519-111-1111 (My Phone Number)
vnd.sec.contact.agg.account_name
vnd.sec.contact.phone

I'm not sure why I have 4 different account or if it helps with this problem. I'm using an S7 running Android 8.0.0

Henrik "The Developer" Lindqvist

unread,
Feb 25, 2021, 10:53:25 AM2/25/21
to Automate
A cursor NullPointerExceptionusually means the query failed, probably due to an invalid column or syntax error in the Where clause. Try...
  • Where clause: contact_id='{split(pickedContactUri, "/")[-1]}' and mimetype='vnd.android.cursor.item/phone_v2' and data2=2
What value does the pickedContactUri variable hold prior to the block?

There's no need to distinct(split(join(result, "\n"), "\n")) as the result is already an Array, just do distinct(result)

aboveth...@gmail.com

unread,
Feb 25, 2021, 2:31:00 PM2/25/21
to Automate
I did try the new where clause but I am getting the same error, I tried selecting different contacts with the same result as well.

The contactURI value is always set to something similar to:
content://com.android.contacts/contacts/lookup/251i11b603620ae7ac55.1450iSkype_775.3338r1093-2D374B394D2D453F3F39434D.847r1122-2D374B394D2D453F3F39434D.1450iSkype_1128/1139

prior to the content block.

Thanks for your help

Henrik "The Developer" Lindqvist

unread,
Feb 26, 2021, 1:13:57 AM2/26/21
to Automate
That contact URI seems okay. Odd, this works as expected on my Android 10 device. Just as a test, try...
    • Content URI: content://com.android.contracts/data
    • Columns: data1
    • Where clause: contact_id=1139 and data2=2
    • Result type: Concatenated rows

    aboveth...@gmail.com

    unread,
    Feb 26, 2021, 1:59:07 AM2/26/21
    to Automate
    Same error.

    Henrik "The Developer" Lindqvist

    unread,
    Feb 26, 2021, 2:01:59 AM2/26/21
    to Automate
    and just...
    • Content URI: content://com.android.contracts/data

    aboveth...@gmail.com

    unread,
    Feb 26, 2021, 2:58:16 AM2/26/21
    to Automate
    There is a lot of data here... I pasted the first three concatenated lines but changed some of the data for privacy, and separated each line with a line feed.

    Seeing a lot of redundancy, and some of the concatenated lines do not appear to contain any phone numbers...

    1613851478757, null, null, null, null, com.google, 87, null, null, 7d9faaa08eba733a, Sauder, Anthony, Sauder, Anthony, null, null, 0, null, 1, null, 1, 0, 1614287241503, null, null, null, 97, 1, null, Anthony Sauder, Anthony Sauder, null, 614, null, null, null, null, null, null, 1, 0, 1, com.google, 1, null, 19, 0, null, 0, 0, null, 1141, null, null, 1, A, em...@website.com, 40, null, 0, 7fc508fd091dd3cb, 0, 0, null, 251i7fc508fd091dd3cb.1450iSkype_638.847r1134-29434F374543594D29512F314B, null, null, S, null, 0, null, null, null, 20, null, null, 0, 7fc508fd091dd3cb, 0, null, Sauder, Anthony, null, null, null, vnd.android.cursor.item/group_membership, null, null, null, null, JQqtQLS6bol/GB9HxPOz6UjKWgk=

    , null, 1613851478757, null, null, null, null, com.google, 87, null, null, 6, Sauder, Anthony, Sauder, Anthony, null, null, 0, null, 1, null, 1, 0, 1614287241503, null, null, null, 97, 1, null, Anthony Sauder, Anthony Sauder, null, 614, null, null, null, null, null, null, 1, 0, 2, com.google, 1, null, 19, 0, null, 0, 0, null, 1141, null, null, 1, A,  em...@website.com, 40, null, 0, 7fc508fd091dd3cb, 0, 0, null, 251i7fc508fd091dd3cb.1450iSkype_638.847r1134-29434F374543594D29512F314B, null, null, S, null, 0, null, null, null, 5, null, null, 0, 7fc508fd091dd3cb, 0, null, Sauder, Anthony, null, null, null, vnd.android.cursor.item/group_membership, null, null, null, null, 7z8+b+6T/6EiAf57Psy0XcwGGsY=

    , null, 1613851478757, null, null, null, null, com.google, 87, null, null, null, Sauder, Anthony, Sauder, Anthony, null, null, 0, null, 1, null, 1, 0, 1614287241503, null, null, null, 97, 1, null, Anthony Sauder, Anthony Sauder, null, 614, null, null, null, null, null, null, 1, 0, 3, com.google, 1, null, 19, 0, null, 0, 0, null, 1141, null, null, 1, A,  em...@website.com, 40, null, 0, 7fc508fd091dd3cb, 0, 0, null, 251i7fc508fd091dd3cb.1450iSkype_638.847r1134-29434F374543594D29512F314B, null, null, S, null, 0, null, 1, null, null, null, null, 0, 7fc508fd091dd3cb, 0, null, Sauder, Anthony, null, null, null, vnd.com.google.cursor.item/contact_misc, null, null, null, null, null, null, 1613851478757, null, null, null, null, com.google, 87, null, null, null, Sauder, Anthony, Sauder, Anthony, null, null, 0, null, 1, null, 1, 0, 1614287241503, null, null, null, 97, 1, null, Anthony Sauder, Anthony Sauder, null, 614, null, null, null, null, null, null, 1, 0, 4, com.google, 1, null, 19, 0, null, 0, 0, null, 1141, null, null, 1, A,  em...@website.com, 40, null, 0, 7fc508fd091dd3cb, 0, 0, null, 251i7fc508fd091dd3cb.1450iSkype_638.847r1134-29434F374543594D29512F314B, null, null, S, null, 0, null, Sauder, Anthony, Anthony Sauder, null, null, 0, 7fc508fd091dd3cb, 0, null, Sauder, Anthony, 1, null, null, vnd.android.cursor.item/name, null, 0, null, null, CRBul3mpWMe+xqE7MtK/tvQuxSA=

    Henrik "The Developer" Lindqvist

    unread,
    Feb 26, 2021, 5:26:13 AM2/26/21
    to Automate

    It was just to test that it works, next try..
    • Content URI: content://com.android.contracts/data
    • Columns: data1,mimetype

    ​ ​man

    unread,
    Sep 5, 2022, 7:52:44 AM9/5/22
    to Automate
    Try putting all values (in WHERE clause) in single quotes. And pay attention to the Content URI, because there's a typo in many posts above:

    Content URI: content://com.android.contacts/data (not contRacts)
    Where clause:  contact_id='{split(pickedContactUri, "/")[-1]}' and mimetype='vnd.android.cursor.item/phone_v2' and and data2='2'

    P. Andreas Schmidt, IVE

    unread,
    Sep 9, 2022, 10:12:11 AM9/9/22
    to Automate
    Or else you can use this Tasker Plugin (it's totally free), where you can specify you want the mobile number:

    https://play.google.com/store/apps/details?id=com.balda.contactstask
    Reply all
    Reply to author
    Forward
    0 new messages