Page 1 of 1

Get number of unread SMS

Posted: 07 Feb 2014 00:37
by michael.heuberger
Can I somehow get the number of unread SMS? Would be awesome!

In my current flow the loop goes forever when I have read an SMS myself upon arrival. I need a condition for counting the number of unread SMS to stop the flow.

Any ideas?

Re: Get number of unread SMS

Posted: 07 Feb 2014 10:26
by Martin
No, it's probably not possible yet.
You could use a trigger App Task Started and assume that all SMS have been read after you are closing the SMS app again.

Re: Get number of unread SMS

Posted: 07 Feb 2014 12:50
by michael.heuberger
Hmmm, why is this not possible yet?

And I am sorry, I cannot follow your suggestion with the App Task Started.

My goal is to write a flow where you get notified for unread SMS messages forever until there are none left. In that loop the screen flashes and the phone vibrates every 15 min. And a dialog appears which asks you if you want to read the message now or later.

How would you do that?

Re: Get number of unread SMS

Posted: 07 Feb 2014 15:24
by Martin
This feature is not available because the SMS database was not officially available to Android developers until Android 4.4 so this feature had a low priority.

My suggestion was meant as some sort of a workaround. When you get an SMS it can be considered unread until you open the SMS app. Of course this won't work when you get 10 SMS, read one and close the SMS app again.

If your device is rooted it might be possible to use the following command to get the unread message count (only tested on Android 4.4):
Execute Root Command: content query --uri content://sms/inbox --where "read=0" --projection "count(*)"

Variable stdout will contain a value like: Row: 0 count(*)=8.

You can use an action Script to extract the number:

Code: Select all

unread_count=substring(stdout, indexOf(stdout, "=")+1);

Re: Get number of unread SMS

Posted: 08 Feb 2014 03:02
by michael.heuberger
Mhhh, I have Android 4.2.1 rooted.

Is there a way I can test the command "content query --uri content://sms/inbox --where "read=0" --projection "count(*)" on a console in my phone first before I go ahead?

Or can you share a flow here and I quickly test it on my phone?

Thanks so much!

Re: Get number of unread SMS

Posted: 08 Feb 2014 10:00
by Martin
The flow is called Show unread SMS count and will be imported into group __test:
http://automagic4android.com/flow.php?i ... 8720f63189

The first action queries the database then the flow uses a script to extract the number from the text (function trim is required because the text returned by the database ends with a newline character). The number of unread SMS will be stored in a variable called unread.
The third action shows the number as a notification on the screen.

You could also use a condition Expression: unread>0 to test if there are unread messages available.

Re: Get number of unread SMS

Posted: 09 Feb 2014 02:57
by michael.heuberger
Thanks, it works! :)