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

浪子不回头ぞ 提交于 2019-11-26 20:16:27

问题


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());
        }
    }

回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/25988574/delete-sms-from-android-on-4-4-4-affected-rows-0zero-after-deleted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!