首页 > 代码库 > android 拦截短信
android 拦截短信
SMSReceiver.java
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 @Override14 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 }
AndroidManifest.xml
<?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>
android 拦截短信
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。