SMS number/name variable help.

126 views
Skip to first unread message

shykitten55

unread,
Jan 4, 2017, 4:31:42 PM1/4/17
to Tasker
I know this may have been asked before, sorry if so.

I am working on an automatic "read SMS" program.

The original code reads the number then the message.

I was thinking that instead of reading the NUMBER, to read the NAME.

Of course that has its own problem:  What if there is no name assigned to the number?
Well, that has me stumped.

I'm guessing I need to test if there is a name assigned, and if there is:  Say the name, otherwise say the number.

But the actual way of doing just that is still beyond me.

I know about the %SMSRF variable - the NUMBER and there is one for the name.
But what happens and what "value" is given to them when there is no name (well, the NAME one more so) when there is no assigned name.....


Thanks.

Raphael Awoseyin

unread,
Jan 6, 2017, 9:37:25 AM1/6/17
to Tasker
You are looking for a variable that Tasker does not expose. I think you have to query Android's SQLite3 Contact tables. I have been struggling with this for a few days now because there are several tables all linked in a complex fashion. You would need to use the %SMSRN and then try to get the display_name from those tables. Unfortunately, I have not found enough Tasker-compatible documentation of those table structures - the ones written for Java don't seem to work with Tasker. For example, the only glib example in the latest Tasker online help makes reference to a table URI like content://com.android.contacts/data/phones. But you won't find such a table called 'phones' in standard documentation.
 

aa bb

unread,
Jan 9, 2017, 3:51:19 AM1/9/17
to Tasker
this task converts number to contactname (if exists, else returns -1)

jGetContactInfo2 (155)
    A1: Java Function [ Return:cr Class Or Object:CONTEXT Function:getContentResolver
{ContentResolver} () Param: Param: Param: Param: Param: Param: Param: ]
    A2: Java Function [ Return:cc Class Or Object:ContactsContract Function:new
{ContactsContract} () Param: Param: Param: Param: Param: Param: Param: ]
    A3: Java Function [ Return:u Class Or Object:Uri Function:parse
{Uri} (String) Param:content://com.android.contacts/phone_lookup Param:unum Param: Param: Param: Param: Param: ]
    <nummer kommt von perform task>
    A4: Java Function [ Return:utel Class Or Object:Uri Function:encode
{String} (String) Param:%par1 Param: Param: Param: Param: Param: Param: ]
    A5: Java Function [ Return:uri Class Or Object:Uri Function:withAppendedPath
{Uri} (Uri, String) Param:u Param:utel Param: Param: Param: Param: Param: ]
    A6: Java Function [ Return:res Class Or Object:cr Function:query
{Cursor} (Uri, String[], String, String[], String) Param:uri Param: Param: Param: Param: Param: Param: ]
    A7: Java Function [ Return:%exists Class Or Object:res Function:moveToFirst
{boolean} () Param: Param: Param: Param: Param: Param: Param: ]
    A8: If [ %exists ~ true ]
    A9: Java Function [ Return:%colnames Class Or Object:res Function:getColumnNames
{String[]} () Param: Param: Param: Param: Param: Param: Param: ]
    A10: Variable Set [ Name:%colNames To:%colnames(:) Recurse Variables:Off Do Maths:Off Append:Off ]
    A11: Java Function [ Return:nameid Class Or Object:res Function:getColumnIndex
{int} (String) Param:display_name Param: Param: Param: Param: Param: Param: ]
    A12: Java Function [ Return:picid Class Or Object:res Function:getColumnIndex
{int} (String) Param:photo_uri Param: Param: Param: Param: Param: Param: ]
    <Kontaktname>
    A13: Java Function [ Return:%out1 Class Or Object:res Function:getString
{String} (int) Param:nameid Param: Param: Param: Param: Param: Param: ]
    <Photo Uri, alternativ Global (jetzt name und photo in der return variable)>
    A14: Java Function [ Return:%out2 Class Or Object:res Function:getString
{String} (int) Param:picid Param: Param: Param: Param: Param: Param: ]
    A15: Variable Join [ Name:%out Joiner:, Delete Parts:On ]
    A16: Return [ Value:%out Stop:On ]
    A17: Else
    A18: Return [ Value:-1 Stop:On ]

(A9 + A10 not necessary, only needed if you want names from other columns)

use with perform task, %par1 is phone number, return variable is %out (com.android.contacts/phone_lookup may differ, havn't found a better way for phonelookup uri yet)

aa bb

unread,
Jan 9, 2017, 2:04:04 PM1/9/17
to Tasker
sorry for doublepost,

just noticed A2 also not needed

aa bb

unread,
Jan 9, 2017, 2:46:12 PM1/9/17
to Tasker
sorry again,

instead

  A3: Java Function [ Return:u Class Or Object:Uri Function:parse
{Uri} (String) Param:content://com.android.
contacts/phone_lookup Param:unum Param: Param: Param: Param: Param: ]

  A3: Java Function [ Return:u Class Or Object:Uri Function:parse
{Uri} (String) Param:content://com.android.
contacts/phone_lookup Param: Param: Param: Param: Param: Param: ]
 
(no second param, unum is old leftover from testing something, dont know why tasker exports this)

Raphael Awoseyin

unread,
Jan 9, 2017, 2:51:37 PM1/9/17
to tas...@googlegroups.com

Here is what I now have%

getContactInfo (3)
A1: Variable Set [ Name:%par1 To:+2347086458888 Recurse Variables:Off Do Maths:Off Append:Off ]
A2: Java Function [ Return:cr Class Or Object:CONTEXT Function:getContentResolver
{ContentResolver} () Param: Param: Param: Param: Param: Param: Param: ]

A3: Java Function [ Return:u Class Or Object:Uri Function:parse

{Uri} (String) Param:content://com.android.contacts/phone_lookup Param: Param: Param: Param: Param: Param: ]

A4: Java Function [ Return:utel Class Or Object:Uri Function:encode
{String} (String) Param:%par1 Param: Param: Param: Param: Param: Param: ]
A5: Java Function [ Return:uri Class Or Object:Uri Function:withAppendedPath

{Uri} (Uri, String) Param:u, utel Param: Param: Param: Param: Param: Param: ]

A6: Java Function [ Return:res Class Or Object:cr Function:query
{Cursor} (Uri, String[], String, String[], String) Param:uri Param: Param: Param: Param: Param: Param: ]
A7: Java Function [ Return:%exists Class Or Object:res Function:moveToFirst
{boolean} () Param: Param: Param: Param: Param: Param: Param: ]
A8: If [ %exists ~ true ]
A9: Java Function [ Return:%colnames Class Or Object:res Function:getColumnNames
{String[]} () Param: Param: Param: Param: Param: Param: Param: ]
A10: Variable Set [ Name:%colNames To:%colnames(:)  Recurse Variables:Off Do Maths:Off Append:Off ]
A11: Java Function [ Return:nameid Class Or Object:res Function:getColumnIndex

{int} (String) Param:display_name Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: ]

A12: Java Function [ Return:picid Class Or Object:res Function:getColumnIndex

{int} (String) Param:Param:photo_uri Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: ]

A13: Java Function [ Return:%out1 Class Or Object:res Function:getString

{String} (int) Param:Param:nameid Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: ]

A14: Java Function [ Return:%out2 Class Or Object:res Function:getString

{String} (int) Param:Param:picid Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: Param: ]

A15: Variable Join [ Name:%out Joiner:, Delete Parts:On ]
A16: Return [ Value:%out Stop:On ]
A17: Else
A18: Return [ Value:-1 Stop:On ]

A19: End If

When I run it I get this error at A5:
20.51.07/E Java Function: uri -> uri
20.51.07/JU analyse: target: Uri expected: null
20.51.07/JU target: analyse done: Uri: class: android.net.Uri  obj: null partWithoutMods: null static: true const false casted: false
20.51.07/JU analyse: returnval: android.net.Uri expected: null
20.51.07/JU returnval: analyse done: android.net.Uri: class: android.net.Uri  obj: null partWithoutMods: null static: true const false casted: false
20.51.07/JU initClass: class: android.net.Uri  obj: null partWithoutMods: android.net.Uri static: true const false casted: false
20.51.07/JU initClass: retnovar: init with array handling -> class android.net.Uri
20.51.07/JU initClass: class: android.net.Uri  obj: null partWithoutMods: android.net.Uri static: true const false casted: false
20.51.07/JU initClass: target: init with array handling -> class android.net.Uri
20.51.07/JU analyse: param0: u, utel expected: class android.net.Uri
20.51.07/JU param0: analyse done: u, utel: class: ???  obj: null partWithoutMods: null static: false const false casted: false
20.51.07/E param 0 class: class android.net.Uri
20.51.07/E param 1 class: class java.lang.String
20.51.07/E targetClass: class android.net.Uri
20.51.07/E object: null
20.51.07/E method: public static android.net.Uri android.net.Uri.withAppendedPath(android.net.Uri,java.lang.String)
20.51.07/E arg0 class null value null
20.51.07/E arg1 class null value null
20.51.07/E Java Function: java.lang.reflect.InvocationTargetException
20.51.07/ Caused by: java.lang.NullPointerException
20.51.07/ android.net.Uri.withAppendedPath(Uri.java:2291)
20.51.07/ java.lang.reflect.Method.invokeNative(Native Method)
20.51.07/ java.lang.reflect.Method.invoke(Method.java:525)
20.51.07/ net.dinglisch.android.taskerm.ExecuteService.c(Unknown Source)
20.51.07/ net.dinglisch.android.taskerm.ExecuteService.a(Unknown Source)
20.51.07/ net.dinglisch.android.taskerm.ExecuteService.a(Unknown Source)
20.51.07/E result: stop task (error)
20.51.07/E Error: 1
20.51.07/MacroEdit action finished exeID 1 action no 4 code 664 status: Err next 4


--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/4VneJMJvp8U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

aa bb

unread,
Jan 9, 2017, 3:02:05 PM1/9/17
to Tasker
A5: Java Function [ Return:uri Class Or Object:Uri Function:withAppendedPath
{Uri} (Uri, String) Param:u, utel Param: Param: Param: Param: Param: Param: ]

A5: Java Function [ Return:uri Class Or Object:Uri Function:withAppendedPath
{Uri} (Uri, String) Param:u Param:utel Param: Param: Param: Param: Param: ]





Am Montag, 9. Januar 2017 20:51:37 UTC+1 schrieb Raphael Awoseyin:

Here is what I now have%

getContactInfo (3)
A1: Variable Set [ Name:%par1 To:+********** (dont know if you or mod can edit and remove the phone number 

To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.

Raphael Awoseyin

unread,
Jan 9, 2017, 3:09:00 PM1/9/17
to tas...@googlegroups.com

Hurray! Now no errors! Thanks!
What modifications do I need to make to get other info,  especially from a custom field in the Google Contacts?


To unsubscribe from this group and all its topics, send an email to tasker+unsubscribe@googlegroups.com.

aa bb

unread,
Jan 9, 2017, 3:38:53 PM1/9/17
to Tasker
Available colum names are stored in the global tasker variable %colNames or here https://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html
you can get the value of them like in A11 and A13 (e.g. last_time_contacted instead of display_name)

custom fields, honestly, no idea yet. I will try to find a solution in the next days or maybe someone else has a idea/solution. sorry


Raphael Awoseyin

unread,
Jan 9, 2017, 3:45:10 PM1/9/17
to Tasker
Many thanks again. I modified your procedure to list all available columns in the phone_lookup table. The challenge now is to know which table contains the custom fields, which is what I really need for my project.

Rich D

unread,
Jan 9, 2017, 7:04:15 PM1/9/17
to Tasker Google Groups Post

this task converts number to contactname


Tasker already has a action for this.

action / phone / test Phone
'

And I believe the new action / file / SQL query will work for this as well. 

Raphael Awoseyin

unread,
Jan 10, 2017, 1:52:31 AM1/10/17
to Tasker

Wow! Fantastic! I was not aware of the Test Phone action that gives so much information. Thanks a lot.
Do you have an idea of the SQL parameters to get information on <b>custom</b> fields in the Contacts?

Rich D

unread,
Jan 10, 2017, 5:06:36 AM1/10/17
to Tasker Google Groups Post

Do you have an idea of the SQL parameters to get information on <b>custom</b> fields in the Contacts?

Sorry, no.   I was hoping you knew sqlite. I have only seen posts by users that do it this way.  I have seen posts by others that use sqlite to get contact info and now pent has added a action for sqlite.  Here is one post.



Raphael Awoseyin

unread,
Jan 10, 2017, 5:41:41 AM1/10/17
to Tasker
I have used SQLite with Tasker on a database I created. As implemented in Tasker, one must know the database file name or URI of the table to query. I am yet to see the database/table name or ths URI to query for the custom fields in Google Contact.

Cat

unread,
Jan 10, 2017, 3:04:34 PM1/10/17
to tas...@googlegroups.com

This thread has kinda gone "off topic"......

LUCKILY I think I have got around the problem with my name vs. Number problem by using the name.

It seems the name is the number if there is no name specified in the "phone book".

Graphic

unread,
Jan 10, 2017, 3:35:29 PM1/10/17
to Tasker
If you had checked the userguide you would have known this:


Text From/Date/Subject/Time (monitored)
"Name is set to sender address if no contact could be looked up."

Using Flashes in actions and checking the userguide will resolve alot of issues...

Cat

unread,
Jan 10, 2017, 3:45:58 PM1/10/17
to tas...@googlegroups.com
Yeah, Graphic.....

Things are easy in retrospect.

I couldn't/didn't find that ORIGINALLY and so I asked....


--

Raphael Awoseyin

unread,
Jan 10, 2017, 4:11:55 PM1/10/17
to Tasker


On Tuesday, 10 January 2017 21:45:58 UTC+1, shykitten55 wrote:
Yeah, Graphic.....

Things are easy in retrospect.

I couldn't/didn't find that ORIGINALLY and so I asked....

On 11 January 2017 at 07:35, Graphic <flaviode...@gmail.com> wrote:
If you had checked the userguide you would have known this:


Text From/Date/Subject/Time (monitored)
"Name is set to sender address if no contact could be looked up."

Using Flashes in actions and checking the userguide will resolve alot of issues...

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/4VneJMJvp8U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.

Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

What I keep discovering is that Tasker is ever more powerful than I have discovered. Some of the great capabilities are documented in the less obvious places and some not documented at all. Honestly, I would never have thought that querying Contacts for info would be under "Test Phone" - especially when there is actually an Action called "Contacts". The latest UserGuide does not even say exactly what information you could get under "Test Phone" - it just says "Test something phone related". So some of us should be forgiven for asking questions that are already answered by Tasker!

Graphic

unread,
Jan 10, 2017, 5:20:25 PM1/10/17
to Tasker
Some of the great capabilities are documented in the less obvious places and some not documented at all. Honestly, I would never have thought that querying Contacts for info would be under "Test Phone" - especially when there is actually an Action called "Contacts". The latest UserGuide does not even say exactly what information you could get under "Test Phone" - it just says "Test something phone related". So some of us should be forgiven for asking questions that are already answered by Tasker!

In his case the information was there, he actually looked at the userguide just didn't finish reading it, it's ok, he bothered looking for it.
In your case it's not documented and i agree that "Test Phone" is not the best name/location for what it does but i don't know if Pent can change this at this point.

But these are small exceptions, userguide is pretty complete and i'm sure Pent will have no problems in updating what is missing/wrong since he is an extremely devoted developer but with alot of work.
The boolean operators examples in the userguide are not correct for example, wich may confuse anyone trying to use them.
I'm not criticizing shykitten55 since i'm glad to help anyone that needs it, just pointing out that sometimes it's faster to get an answer by looking first at the userguide and do a few tests with the flash action.
Then, there are a few people that don't bother at all looking for anything expecting an answer, still, if the answer is in the userguide i just point them there.

Raphael Awoseyin

unread,
Jan 10, 2017, 5:40:33 PM1/10/17
to tas...@googlegroups.com

You make valid points.

Just in case Pent wants to address the specific issue of "Test Phone",  I suggest to move all the stuff there to the Action called "Contacts", rename that action "Query Contacts", and reserve the "Test Phone" action for querying the capabilities of the phone. Just a suggestion.

--
Reply all
Reply to author
Forward
0 new messages