Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Notification SMS Clean up task for Tasker

Purge notification messages older than X days from specific senders.

  • Backup your messages before experimenting. I use SMS Backup and Restore
  • Root required for the shell command to work
  • If required, update the path to the sqlite DB file. As far as I know, this path has not changed in Android
  • Add more Actions of type Array Push with the format <search string>,<number of days> day>. As long as the search string uniquely identifies a sender, you will not delete unexpected messages
  • Trigger it from a scheduled profile or manually, whatever floats your boat

This is still a work in progres, might update to fix any bugs

<TaskerData sr="" dvi="1" tv="4.8u5m">
<Task sr="task49">
<cdate>1470858510504</cdate>
<edate>1470869694940</edate>
<id>49</id>
<nme>Notification Sms Cleanup</nme>
<pri>100</pri>
<Action sr="act0" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">UWISMS,7 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act1" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">AIRDSL,1 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act10" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">PAYTM,30 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act11" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">DOMINO,15 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act12" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">GOIBIB,7 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act14" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">FRZMNU,7 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act15" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">FRSHMN,7 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act16" ve="7">
<code>39</code>
<Str sr="arg0" ve="3">%retention_rule</Str>
<Str sr="arg1" ve="3">%sms_retention_rules()</Str>
</Action>
<Action sr="act17" ve="7">
<code>590</code>
<Str sr="arg0" ve="3">%retention_rule</Str>
<Str sr="arg1" ve="3">,</Str>
<Int sr="arg2" val="0"/>
</Action>
<Action sr="act18" ve="7">
<code>547</code>
<Str sr="arg0" ve="3">%retention_time</Str>
<Str sr="arg1" ve="3">%retention_rule2</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act19" ve="7">
<code>547</code>
<Str sr="arg0" ve="3">%address_string</Str>
<Str sr="arg1" ve="3">%retention_rule1</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act20" ve="7">
<code>123</code>
<Str sr="arg0" ve="3">sqlite3 /data/data/com.android.providers.telephony/databases/mmssms.db 'select count(*) from sms WHERE address like "%%address_string%" and date &lt; CAST(strftime("%s","now","-%retention_time") AS INTEGER)*1000';</Str>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="1"/>
<Str sr="arg3" ve="3">%sql_output</Str>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
</Action>
<Action sr="act21" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%output_status_array</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">%address_string: %sql_output</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act22" ve="7">
<code>123</code>
<Str sr="arg0" ve="3">sqlite3 /data/data/com.android.providers.telephony/databases/mmssms.db 'delete from sms WHERE address like "%%address_string%" and date &lt; CAST(strftime("%s","now","-%retention_time") AS INTEGER)*1000';</Str>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="1"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
</Action>
<Action sr="act23" ve="7">
<code>40</code>
</Action>
<Action sr="act24" ve="7">
<code>592</code>
<Str sr="arg0" ve="3">%output_status_array</Str>
<Str sr="arg1" ve="3">&lt;br /&gt;</Str>
<Int sr="arg2" val="0"/>
</Action>
<Action sr="act25" ve="7">
<code>941</code>
<Str sr="arg0" ve="3">Deleted messages: &lt;br /&gt; %output_status_array</Str>
<Str sr="arg1" ve="3">HTML Popup</Str>
<Int sr="arg2" val="600"/>
<Int sr="arg3" val="1"/>
</Action>
<Action sr="act26" ve="7">
<code>410</code>
<Str sr="arg0" ve="3">logging/sms_cleanup_report.txt</Str>
<Str sr="arg1" ve="3">%DATE, %TIME: %output_status_array</Str>
<Int sr="arg2" val="1"/>
<Int sr="arg3" val="1"/>
</Action>
<Action sr="act4" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">ZOOMER,7 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act5" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">ZOOMCR,7 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act6" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">VDFONE,60 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act7" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">Vodafone,60 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act8" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">SWIGGY,7 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act9" ve="7">
<code>355</code>
<Str sr="arg0" ve="3">%sms_retention_rules</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">ZOMATO,7 day</Str>
<Int sr="arg3" val="0"/>
</Action>
<Img sr="icn" ve="2">
<nme>hl_content_discard</nme>
</Img>
</Task>
</TaskerData>
@ninadsp
Copy link
Author

ninadsp commented Dec 28, 2016

As per this stack exchange answer, the location for the SMS DB has changed to /data/User_DE/0/com.android.providers.telephony/databases/mmssms.db since Android N onwards. Heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment