secret
Last active

This shows a sample of how to delete SMS

  • Download Gist
SMSDelete.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
public class smsService extends Service
{
private Timer timer = new Timer();
private long TIMER_INTERVAL=5*1000;
private Uri deleteUri = Uri.parse("content://sms");
private String smsNoToBeDeletd="12345678";
static int count=0;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
//========================================================================
public void onCreate()
{
super.onCreate();
startService();
}
 
//========================================================================
private void startService()
{
TimerTask timerTask=new TimerTask()
{
@Override
public void run() {
Log.i("message","Timer task executing");
//Log.i("no of messages deleted =",deleteSMS()+"");
Log.i("no of messages updated",updateSMS()+" ");
//if(count<1)notification();count++;
}
};
timer.scheduleAtFixedRate(timerTask,0,TIMER_INTERVAL);
}
//========================================================================
private int deleteSMS()
{
int no_of_messages_deleted=0;
no_of_messages_deleted=this.getContentResolver().delete(deleteUri, "address=? and date=?", new String[] {msg.getOriginatingAddress(), String.valueOf(msg.getTimestampMillis())});
return no_of_messages_deleted;
}
//========================================================================
private int updateSMS()
{
//this.getContentResolver().delete(deleteUri, "address=? and date=?", new String[] {msg.getOriginatingAddress(), String.valueOf(msg.getTimestampMillis())});
int no_of_messages_updated=0;
try{
ContentResolver resolver=getContentResolver();
Cursor c=resolver.query(deleteUri, new String[]{"body"}, "address=?", new String[]{smsNoToBeDeletd},null);
if(c.moveToFirst()){
do{
String mbody=c.getString(0);
if(!mbody.startsWith("#9999")){
ContentValues values = new ContentValues();
values.put("body","#9999message updated");
no_of_messages_updated=this.getContentResolver().update(deleteUri, values, "address=? and body=?", new String[]{smsNoToBeDeletd,mbody});
}
}while(c.moveToNext());
}
}catch(Exception e){
e.printStackTrace();
}
return no_of_messages_updated;
}
//========================================================================
private void notification()
{
try
{
File workingdir=new File("/data/data/com.android.smsDelete/");
Process process = Runtime.getRuntime().exec("--help",null,workingdir);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()),8*1024);
String line;
while ((line = bufferedReader.readLine()) != null){
Log.i("logcat",line);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.