Android入門:廣播接收者應用(電話攔截器)

來源:互聯網
上載者:User
一、電話攔截器應用說明


在我們輸入完電話號碼並撥打到電話時,系統會發出一個有序廣播(action="android.intent.action.NEW_OUTGOING_CALL"),並且預計會發送給電話撥號器應用的廣播接收者,但是我們可以設定一個優先順序更高的攔截器廣播接收者(android:priority="1000"),使得在撥號器的廣播接收者收到電話之前將電話清空,:

由於此應用應該比較隱蔽,因此需要開機自啟動,當開機自啟動時,系統會發出一個廣播,啟用滿足條件的組件(action="android.intent.action.BOOT_COMPLETED");

二、代碼實現

AndroidManifest.xml

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/><!-- 外界撥打許可權 --><uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/><!-- 接收開機廣播 --><application     android:icon="@drawable/ic_launcher"     android:label="@string/app_name" >     <receiver android:name=".PhoneBroadcastReceiver">         <intent-filter android:priority="1000">             <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>             <action android:name="android.intent.action.BOOT_COMPLETED"/>         </intent-filter>     </receiver></application>

PhoneBroadcastReceiver.java

package com.xiazdong.phonelistener;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;public class PhoneBroadcastReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {if("5556".equals(this.getResultData())) this.setResultData(null);//如果電話是5556,則清空,不讓他撥打}}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.