码迷,mamicode.com
首页 > 移动开发 > 详细

android 拦截短信

时间:2014-09-18 11:00:23      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   color   io   os   java   ar   

SMSReceiver.java

bubuko.com,布布扣
 1 package com.gbg.mybroadcastreceiver;
 2 
 3 import android.content.BroadcastReceiver;
 4 import android.content.Context;
 5 import android.content.Intent;
 6 import android.os.Bundle;
 7 import android.telephony.SmsMessage;
 8 import android.util.Log;
 9 import android.widget.Toast;
10 
11 public class SMSReceiver extends BroadcastReceiver {
12 
13     @Override
14     public void onReceive(Context context, Intent intent) {
15         Log.i("app", "shoudao");
16         Bundle bundle = intent.getExtras();
17         Object messages[] = (Object[])bundle.get("pdus");
18         SmsMessage smsMessage[] = new SmsMessage[messages.length];
19         for (int i = 0; i < smsMessage.length; i++) {
20             smsMessage[i] = SmsMessage.createFromPdu((byte[])messages[i]);
21         }
22         Toast.makeText(context, "您有"+messages.length+"条短信。。。", 1).show();;
23     }
24 
25 }
View Code

 

 

 

AndroidManifest.xml

bubuko.com,布布扣
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gbg.mybroadcastreceiver"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity">
            <intent-filter >
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <service android:name=".LocalService" android:process="com.gbg.mybroadcastreceiver.localservice"  android:enabled="true">
            <intent-filter android:priority="1000">
                <category android:name="com.gbg.localservice"/>
            </intent-filter>
        </service>
        <receiver android:name="com.gbg.mybroadcastreceiver.SMSReceiver" android:enabled="true">
            <intent-filter android:priority="999">
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </receiver>
    </application>

</manifest>
View Code

 

android 拦截短信

标签:android   style   blog   http   color   io   os   java   ar   

原文地址:http://www.cnblogs.com/mrgong/p/3978572.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!