Android 将新未接来电设置为“旧”
我想重置所有丢失的电话,到目前为止我已经重置了Android 将新未接来电设置为“旧”,android,Android,我想重置所有丢失的电话,到目前为止我已经重置了 public void resetMissingCalls() { Runnable reset = new Runnable() { @Override public void run() { Utils.PrintInfo("resetMissingCalls.run"); String[] projection = { CallLog.Calls._ID
public void resetMissingCalls() {
Runnable reset = new Runnable() {
@Override
public void run() {
Utils.PrintInfo("resetMissingCalls.run");
String[] projection = { CallLog.Calls._ID,
CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.TYPE };
String where = CallLog.Calls.TYPE + "=" + CallLog.Calls.MISSED_TYPE
+ " AND " + CallLog.Calls.NEW + "=1";
Cursor c = getContentResolver().query(
CallLog.Calls.CONTENT_URI, projection, where, null, null);
Utils.PrintInfo("CALLS " + c.getCount());
c.moveToFirst();
if (c.getCount() > 0) {
do {
Utils.PrintInfo("coursor");
setAsRead(c.getString(c
.getColumnIndex(CallLog.Calls._ID)));
} while (c.moveToNext());
}
c.close();
}
};
new Handler().post(reset);
}
public void setAsRead(String id) {
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
// Number
Builder builder = ContentProviderOperation
.newUpdate(CallLog.Calls.CONTENT_URI);
builder.withSelection(
ContactsContract.Data.CONTACT_ID + "=?",
new String[] {
id });
builder.withValue(CallLog.Calls.NEW, "0");
ops.add(builder.build());
// Asking the Contact provider to create a new contact
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
e.printStackTrace();
Utils.PrintError("Exception: " + e.getMessage());
}
}
我已经自己修复了,只需将setAsRead方法更改为
public void setAsRead(String id) {
ContentValues values = new ContentValues();
values.put(CallLog.Calls.NEW, Integer.valueOf(0));
String[] fv = new String[] { id };
getContentResolver().update(CallLog.Calls.CONTENT_URI, values,
CallLog.Calls._ID + "= ?", fv);
}
public void setAsRead(String id) {
ContentValues values = new ContentValues();
values.put(CallLog.Calls.NEW, Integer.valueOf(0));
String[] fv = new String[] { id };
getContentResolver().update(CallLog.Calls.CONTENT_URI, values,
CallLog.Calls._ID + "= ?", fv);
}