Get number of unread SMS

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

Locked
michael.heuberger
Posts: 27
Joined: 04 Feb 2014 09:19

Get number of unread SMS

Post by michael.heuberger » 07 Feb 2014 00:37

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?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Get number of unread SMS

Post by Martin » 07 Feb 2014 10:26

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.

michael.heuberger
Posts: 27
Joined: 04 Feb 2014 09:19

Re: Get number of unread SMS

Post by michael.heuberger » 07 Feb 2014 12:50

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?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Get number of unread SMS

Post by Martin » 07 Feb 2014 15:24

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);

michael.heuberger
Posts: 27
Joined: 04 Feb 2014 09:19

Re: Get number of unread SMS

Post by michael.heuberger » 08 Feb 2014 03:02

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!

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Get number of unread SMS

Post by Martin » 08 Feb 2014 10:00

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.

michael.heuberger
Posts: 27
Joined: 04 Feb 2014 09:19

Re: Get number of unread SMS

Post by michael.heuberger » 09 Feb 2014 02:57

Thanks, it works! :)

Locked