Delete SMS from android on 4.4.4 (Affected rows = 0(Zero), after deleted)
Asked Answered
B

2

9

i want to send SMS from my android device and delete it from mydevice(Sent messages).

SMS are saved in device(4.4.4) but SMS is not deleted with my code. after delete rows affected = 0(Zero).

My device vesrion is 4.4.4.

In other devices, SMS are not being saved. Why does SMS's are saved in Android 4.4.4?

I dont want to save my sent sms's or failure sms's(Which are not sent).

please help me.

My permissions

<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />

My Code is to send SMS

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, msg, null, null);

I am calling the method deleteSMS() from handler with postdelay of 5seconds

Handler handler = new Handler();
handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                String message = CastApplication.mPref.getString(context.getResources().getString(R.string.pref_message_to_friend), "");
                deleteSMS(context, message, number);

                if (MyCastFragment.getInstance() != null) {
                    MyCastFragment.getInstance().updateView();
                }

                progressDialog.dismiss();
                context.finish();
            }
        }, 5000);

Delete SMS

public void deleteSMS(Context ctx, String message, String number) {
        try {
            Uri uriSms = Uri.parse("content://sms");
            Cursor c = ctx.getContentResolver().query(uriSms,
                new String[] { "_id", "thread_id", "address",
                    "person", "date", "body" }, null, null, null);

            Log.i(TAG, "c count......"+c.getCount());
            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(3);
                    Log.e("log>>>", "0>" + c.getString(0) + "1>" + c.getString(1)   + "2>" + c.getString(2) + "<-1>"  + c.getString(3) + "4>" + c.getString(4)+ "5>" + c.getString(5));
//                    Log.e("log>>>", "date" + c.getString(0));

//                    if (body.contains(getResources().getText(R.string.invite_text).toString()) && address.equals(number)) {
                    if (message.equals(body) && address.equals(number)) {
                        // mLogger.logInfo("Deleting SMS with id: " + threadId);
                        int rows = ctx.getContentResolver().delete(Uri.parse("content://sms/" + id), "date=?",new String[] { c.getString(4) });
                        Log.e("log>>>", "Delete success......... rows: "+rows);
                        Log.e("log>>>", "Delete success......... body: "+body);
                    }
                } while (c.moveToNext());
            }

        } catch (Exception e) {
            Log.e("log>>>", e.toString());
            Log.e("log>>>", e.getMessage());
        }
    }
Bedrail answered 23/9, 2014 at 6:44 Comment(8)
how u resolved your issue ?Weinshienk
@ErumHannan No. As per below answer, it is not possibleBedrail
i have successfuly removed my all inbox messages would u want to do the same ?Weinshienk
Presently, No need. project is completed. Share below , It may be useful to some oneBedrail
what was your project means were u deleting the sms from inbox ??Weinshienk
Erum, I am not deleting SMS. Share it below I use when ever I need. Thank you.Bedrail
Let us continue this discussion in chat.Weinshienk
c.getString(4) : But date is in the third columnNatatory
T
10

Unless your app is marked as default SMS app in device, you wont be able to play with SMS Provider, please read SMS guidelines for the same for KITKAT

Teredo answered 23/9, 2014 at 7:20 Comment(6)
Thank you for reply, Can you please tell how to mark my app as Default SMS app ?Bedrail
@GangadharNimbally That link tells you what you need to do for your app to be a default. It's not a trivial task, as your app will then be responsible for many things it probably doesn't already handle.Fragmentary
@Mike M, Is there any sample app to become default SMS app. Please share it I am poor at androidBedrail
@GangadharNimbally Not that I know of. The place to start, though, is with that link. Copy the manifest and add the necessary permissions (there's about 5 or 6 needed, IIRC), create at least a temporary main launcher Activity, compile and run it once, and make sure it shows in the list of eligible default SMS apps. That'll be the bare minimum. Then start adding the additional functionalities. Of course, you could always check out the source code for the AOSP SMS app for a full implementation.Fragmentary
@GangadharNimbally follow the link and code suggested into it, its already mentioned there how to make you app default, read the article carefully.Teredo
if jast with defaul app ca filter sms : so How Vault filter and delete sms however its not default app !!Perdomo
C
-1

App can delete Sms at Kitkat WITHOUT default sms app granted.

You need only WRITE_SMS permission and AppOpps manipulation.

After that your sms can be deleted after 10 seconds after receiving, notification also will despear.

Cordage answered 19/3, 2016 at 21:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.