SmsReceiver.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:phonk 作者:
@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();
    if (extras == null)
        return;

    // To display mContext Toast whenever there is an SMS.
    // Toast.makeText(mainScriptContext,"Recieved",Toast.LENGTH_LONG).show();

    Object[] pdus = (Object[]) extras.get("pdus");
    for (int i = 0; i < pdus.length; i++) {
        SmsMessage SMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
        String sender = SMessage.getOriginatingAddress();
        String body = SMessage.getMessageBody().toString();

        // A custom Intent that will used as another Broadcast
        Intent in = new Intent("SmsMessage.intent.MAIN").putExtra("get_msg", sender + ":" + body);

        // You can place your check conditions here(on the SMS or the
        // sender)
        // and then send another broadcast
        context.sendBroadcast(in);

        // This is used to abort the broadcast and can be used to silently
        // process incoming message and prevent it from further being
        // broadcasted. Avoid this, as this is not the way to program an
        // app.
        // this.abortBroadcast();
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号