开发学院手机开发Android 开发 Android Call Log and SMS Delete 电话记录和短信... 阅读

Android Call Log and SMS Delete 电话记录和短信删除

 2010-07-19 23:02:00 来源:WEB开发网   
核心提示:}@Overridepublic void onChange(boolean selfChange) {super.onChange(selfChange);Cursor c = context.getContentResolver().query(uriCall,new String[] { "_id&qu

}

@Override

public void onChange(boolean selfChange) {

super.onChange(selfChange);

Cursor c = context.getContentResolver().query(uriCall,

new String[] { "_id", "number", "date" }, null, null, null);

if (c != null && c.moveToFirst()) {

String num = c.getString(1);

String id = c.getString(0);

if (num != null && num.equals(phoneNum)) {

context.getContentResolver().delete(uriCall, "_id=" + id,

null);

}

// for(int i =0; i < c.getColumnCount(); i++)

// {

// String strColumnName = c.getColumnName(i);

// String strColumnValue = c.getString(i);

// Log.e("i", "i="+i);

// Log.e("strColumnName", "strColumnName="+strColumnName);

// Log.e("strColumnValue", "strColumnValue="+strColumnValue);

// }

c.close();

}

}

}

调用

Java代码

context.getContentResolver()

.registerContentObserver(

Uri.parse("content://call_log"),

true,

new CallContentObserver(context,

phoneNumber, null));

context.getContentResolver()

.registerContentObserver(

Uri.parse("content://call_log"),

true,

new CallContentObserver(context,

phoneNumber, null));

通过调用ContentObserver,当数据库变化后,才会处理。。此方法可用于如SMS删除,而不用Thread.sleep(不要用Sleep,因为效果非常差,有时无法删除)

短信可用下面的

Java代码

private final static String strUriInbox = "content://sms/inbox";

private final static Uri uriSms = Uri.parse(strUriInbox);

private final static String strUriInbox = "content://sms/inbox";

private final static Uri uriSms = Uri.parse(strUriInbox);

Java代码

Cursor c = context.getContentResolver().query(

uriSms,

new String[] { "_id", "thread_id", "address",

"person", "date", "body" }, null, null,

null);

上一页  1 2 

Tags:Android Call Log

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接