简体   繁体   中英

how to delete log from last call only?

Using the following code i can delete calls from particular numbers, which works fine only it very slow and the app becomes unresponsive while the code is running (especially if the is a lot of calls in the log)

so what i really want is for it to only check the last call in the log and not go though the hole log.

String strUriCalls = "content://call_log/calls";
    Uri UriCalls = Uri.parse(strUriCalls);
    Cursor c = context.getContentResolver().query(UriCalls, null, null,
            null, null);
    if (c.getCount() <= 0) {
        Toast.makeText(context, "Call log empty", Toast.LENGTH_SHORT)
                .show();
    }

    while (c.moveToNext()) {
        SharedPreferences sp = PreferenceManager
                .getDefaultSharedPreferences(context);
        String gonnabprefd = sp.getString("callerase", null);
        String[] numarry = gonnabprefd.split(" ");
        for (int i = 0; i < numarry.length; i++) {
            String gonnabpref = numarry[i];
            String queryString = "NUMBER='" + gonnabpref + "'";
            Log.v("Numberimcomingreciver ", queryString);
            int b = context.getContentResolver().delete(UriCalls,
                    queryString, null);
            if (b >= 1) {
                Toast.makeText(context, "deleted", Toast.LENGTH_LONG)
                        .show();}}

Hate to answer my own question but removing

while (c.moveToNext()) {

worked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM