仅供技术研究,莫用于非法用途= =!
1.配置广播接收者:
<receiver android:name="com.guangwei.sms.receiver.SmsReceiver" >//需要一个广播接收者,下面创建
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />//拦截的广播
</intent-filter>
</receiver>
2.新建SmsReceiver继承自BroadcastReceiver
代码如下:
public class SmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Object[] pdus = (Object[]) intent.getExtras().get("pdus");
for (Object obj : pdus) {
SmsMessage msg = SmsMessage.createFromPdu((byte[]) obj);
String address = msg.getOriginatingAddress();
String body = msg.getMessageBody();
System.out.println("收到短信了:" + body + ";发信人:" + address);
abortBroadcast();//中断广播的传递
}
}
}
如果运行时需要权限的话,找到报错提示的权限加上.
备注:仅供技术研究,莫用于非法用途= =!