Skip to content

@vivdub /SMSDelete.java secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
This shows a sample of how to delete SMS
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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.