现在的位置: 首页 > 综合 > 正文

How to filter SMS message containg certain keyword

2013年01月16日 ⁄ 综合 ⁄ 共 782字 ⁄ 字号 评论关闭

What is important :

abortBroadcast();
filter.setPriority(1000);

It works (I use in my app GPSDetective - you can dl on the android market)

Sample code :

     BroadcastReceiver br;

     @Override
     public void onCreate()
         {
         super.onCreate();

         br = new BroadcastReceiver()
             {
             @Override
             public void onReceive(Context ctx, Intent intent)
                 {
                 Bundle extras = intent.getExtras();
                 SmsMessage[] sms = null;
                 if (extras != null)
                     {
                     //read the content of the SMS and do what you want
                     if (bKeepThisSMSforMyApp=true)
                         abortBroadcast();
                     }
                 }
             };
         IntentFilter filter = new IntentFilter();
         filter.addAction("android.provider.Telephony.SMS_RECEIVED");
         filter.setPriority(1000);
         registerReceiver(br, new IntentFilter(filter));
         }

抱歉!评论已关闭.