c2alvaro
03/05/17, 14:46:00
Saludos, quiero eliminar mensajes SMS por medio de codigo, tengo un botón <Eliminar> donde primero recorro todos los mensajes y comparo si el SMS es del número que quiero eliminar para obtener su id, luego procedo a eliminar pero siempre me devuelve cero (0) no elimina, estoy ejecutado la aplicación en la API 22 5.1.1 espero sus comentarios gracias.
Nota: ya intente usando el thread_id, tambien ya intente con getString(), getLong()
xBtnEliminar.setOnClickListener(new View.OnClickListener() {
override
public void onClick(View v) {
xTxtCampo.setText("");
int row = 0;
String numeroBorrar="04263135816";
Uri uri = Uri.parse("content://sms/");
String[] projeccion = new String[] {"_id","thread_id","address"};
Cursor c = getContentResolver().query(
uri, projeccion, null, null, null);
while(c.moveToNext()){
String numero=c.getString(2);
if (numero.equals(numeroBorrar)){
Uri uri2 = Uri.parse("content://sms/"+c.getInt(0));
row = getContentResolver().delete(uri2,null,null);
mRowsDeleted = mRowsDeleted + row;
}
}
c.close();
xTxtCampo.setText("Delete: " + mRowsDeleted);
}
});
}
Nota: ya intente usando el thread_id, tambien ya intente con getString(), getLong()
xBtnEliminar.setOnClickListener(new View.OnClickListener() {
override
public void onClick(View v) {
xTxtCampo.setText("");
int row = 0;
String numeroBorrar="04263135816";
Uri uri = Uri.parse("content://sms/");
String[] projeccion = new String[] {"_id","thread_id","address"};
Cursor c = getContentResolver().query(
uri, projeccion, null, null, null);
while(c.moveToNext()){
String numero=c.getString(2);
if (numero.equals(numeroBorrar)){
Uri uri2 = Uri.parse("content://sms/"+c.getInt(0));
row = getContentResolver().delete(uri2,null,null);
mRowsDeleted = mRowsDeleted + row;
}
}
c.close();
xTxtCampo.setText("Delete: " + mRowsDeleted);
}
});
}