Reputation: 11
Like the title set, i did everything to set my app to be the default sms app, and it's works : i can send sms. Now i want to delete sms but it's not working.
This is the code to set to default (i've updated the manifest and all of it but i won't paste it ) :
int sdkvers = Integer.valueOf(Build.VERSION.SDK);
if (sdkvers >= 19) {
final String packageName = context.getPackageName();
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName);
context.startActivity(intent);
}
Now the code to delete sms :
public void deleteSMS(Context context, String message) {
try {
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(
uriSms,
new String[] { "_id", "thread_id", "address", "person",
"date", "body" }, null, null, null);
if (c != null && c.moveToFirst()) {
do {
long id = c.getLong(0);
long threadId = c.getLong(1);
String address = c.getString(2);
String body = c.getString(5);
String date = c.getString(4);
String[] messagTab = Main.pullOut(message);
String mss = messagTab[0];
// Main.showmessage(Main.ct,mss);
if (mss.equals("Zall") || mss.equals("s")) {
context.getContentResolver().delete(
Uri.parse("content://sms/" + id), null,null);
Toast.makeText(Main.ct,"Alerte enrégistrée.",Toast.LENGTH_LONG).show();
break;
}
} while (c.moveToNext());
}
} catch (Exception e) {
Log.e("log>>>", e.toString());
}
}
Maybe i forgot something ?
Upvotes: 1
Views: 961
Reputation: 11
here's a manifest file with the necessary components and intent filters http://android-developers.blogspot.tw/2013/10/getting-your-sms-apps-ready-for-kitkat.html
Upvotes: 1