A profile to detect when a SMS database has been changed

http://webmail.dev411.com/t/gg/tasker/12bdddbsak/a-profile-to-detect-when-a-sms-has-been-sent

A belated reply. My solution below [let Tasker know when an SMS was sent]
follows Pent's outline.

Prereqs - you must:

0. be root
0. have sqlite3 installed
0. locate your message database (mmssms.db). Most likely this is in
</data/data/com.android.providers/telephony/databases/mmssms.db>

1. Create a Profile with the context of Application - Messages (or whichever SMS apps you care about).

2. On-entry task:
  2a.- Script Action, Run Shell, Command:
       - sqlite3 [your message db full path] SELECT MAX(_id) FROM sms ;
       - store output in %PrevMaxMsg

3. On-exit task:
  3a.- Script Action, Run Shell, Command:
       - sqlite3 [your message db full path] SELECT MAX(_id) FROM sms ;
       - store output in %NowMaxMsg
  3b. - If %PrevMaxMsg !~ %NowMaxMsg:
      3c. - [your actions]

This works because the mmssms.db database contains a table (sms) which
holds the details of sms and mms messages drafted, sent, received and
failed. Getting and comparing MAX(_id) on entry and exit lets you know if a
new message has been created.

4. Note with this approach "[your actions]" will also occur for a drafted,
unsent message - this may be undesirable. For more granularity:
   - replace the SQL queries in 2a and 3a with something like "SELECT type,
COUNT(*) FROM sms GROUP BY type ;"
   - This results in "1|47 2|43 3|1 6|1", which are message states and
counts "1. Inbox (Received) = 47; 2. Sent = 43; 3. Draft = 1; 6. Queued
(for Send) = 1". These counts could be used to drive different behaviours.
   - I understood the message states from
<https://github.com/android/platform_frameworks_base/blob/ics-mr1-release/core/java/android/provider/Telephony.java>

 

posted @ 2015-05-17 16:42  IAmAProgrammer  阅读(351)  评论(0编辑  收藏  举报