安卓簡訊過濾器小程式,安卓過濾器小程式

來源:互聯網
上載者:User

安卓簡訊過濾器小程式,安卓過濾器小程式

對於安卓的簡訊廣播接受者支援,Google應該在安卓4.2以後就開始弱化了,也就是配置起來較麻煩唯一,但是到了5.0的時候就應該完全不支援了。因為Google認為這種技術對使用者個人隱私造成很大影響,事實上也正是如此,駭客可以很容易的擷取到使用者的簡訊。
下面寫一個簡訊過濾的小demo。

/**建立一個簡訊接收器,繼承廣播接受者*/public class SmsReceiver extends BroadcastReceiver {    @Override    public void onReceive(Context context, Intent intent) {        System.out.println("簡訊到來了。 。。。");        Object[] objs = (Object[]) intent.getExtras().get("pdus");        for (Object obj : objs) {            // 得到簡訊對象            SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) obj);            String body = smsMessage.getMessageBody();            String sender = smsMessage.getOriginatingAddress();            System.out.println("body:" + body);            System.out.println("sender:" + sender);            // 終止掉當前的廣播。            if ("5556".equals(sender)) {                abortBroadcast();            }        }    }}

需要在在AndroidManifest.xml配置對應的許可權:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.itheima.smsreceiver"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="17" />    <uses-permission android:name="android.permission.RECEIVE_SMS"/> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.itheima.smsreceiver.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <receiver android:name="com.itheima.smsreceiver.SmsReceiver">            <intent-filter android:priority="1000">                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>            </intent-filter>        </receiver>          <!-- 配置廣播接受者 -->        <receiver android:name="com.itheima.smsreceiver.OutCallReceiver">            <intent-filter android:priority="1000">                <!-- 配置廣播接收者關心的事件是撥出電話 -->                <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>            </intent-filter>        </receiver>    </application></manifest>

然後類比給手機發簡訊,就能攔截簡訊了。

Log資訊:

聯繫我們

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