通过应用验证短信之前,向用户显示 [英] Verify sms text message by app before it displayed to user

查看:129
本文介绍了通过应用验证短信之前,向用户显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有在Android中的一个选项,以验证短信的话
前屏幕用户上显示吗?
我可以阻止特定文本这个文本消息,在code控制它?

Do we have an option in Android to verify sms text words before displaying it on the screen to user? Can I block this text message with specific text, controlling it in code?

有关这件事的任何想法或教程?

Any ideas or tutorials about this thing?

推荐答案

您可以使用广播接收器获得进入短信

you can use BroadcastReceiver to get the incoming sms

public class SmsReceiver extends BroadcastReceiver {

private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";


@Override
public void onReceive(Context context, Intent intent) {
    // Log.i(TAG, "Intent received: " + intent.getAction());

    if (intent.getAction().equals(SMS_RECEIVED)) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            final SmsMessage[] messages = new SmsMessage[pdus.length];
            for (int i = 0; i < pdus.length; i++) {
                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            }
            if (messages.length > -1) {                 

                  String str=messages[0].getMessageBody();

                  if(check for the text in the string str)
                  {                      
                      abortBroadcast();//stops msg from reaching inbox                   
                  } 

              }
          }
      }
  }
}

这些权限添加到您的清单。

add these permissions to your manifest

<uses-permission android:name="android.permission.RECEIVE_SMS"/>    
<uses-permission android:name="android.permission.READ_SMS" />

添加接收到你的清单

<receiver android:name=".SmsReceiver" >
        <intent-filter android:priority="999">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" >
            </action>
        </intent-filter>
    </receiver>

这篇关于通过应用验证短信之前,向用户显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆