Android 手機衛士8--刪除通話記錄,android8--

來源:互聯網
上載者:User

Android 手機衛士8--刪除通話記錄,android8--

1.編寫代碼需要注意bug:

再刪除通話記錄的時候,刪除的是以前的通話記錄,本次攔截下來的電話號碼,通話記錄沒有刪除??????
問題原因:資料庫中本次通話記錄的電話號碼還沒有插入,就做了刪除操作

2.bug解決方案:

內容提供者:對外提供資料庫的訪問方式
內容解析器:用內容提供者提供的訪問方式Uri,訪問資料庫(增刪改查)
內容觀察者:觀察資料庫的變化,一旦資料發生改變,調用相應方法

通過內容觀察者,觀察資料庫的插入,一旦有插入,則做刪除此條插入資料操作

public void endCall(String phone) {......//6,在內容解析器上,去註冊內容觀察者,通過內容觀察者,觀察資料庫(Uri決定那張表那個庫)的變化mContentObserver = new MyContentObserver(new Handler(),phone);getContentResolver().registerContentObserver(Uri.parse("content://call_log/calls"), true, mContentObserver);}}

 

class MyContentObserver extends ContentObserver{private String phone;public MyContentObserver(Handler handler,String phone) {super(handler);this.phone = phone;}//資料庫中指定calls表發生改變的時候會去調用方法@Overridepublic void onChange(boolean selfChange) {//插入一條資料後,再進行刪除getContentResolver().delete(Uri.parse("content://call_log/calls"), "number = ?", new String[]{phone});super.onChange(selfChange);}}

  

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.