android 通过android.provider.Telephony.SMS_RECEIVED 不能正确的捕获短信接收信号

文章标签: android-intent,android
2014-11-8 13:36:15     38 人阅读    

如题在短信接收的时候无法捕获到具体的信息号,下面是我的service代码,  我尝试捕获Intent.ACTION_SCREEN_ON 和 Intent.ACTION_SCREEN_OFF 成功,但是在捕获 SMS_RECEIVED 的时候就不行了。下面是哪里错误了?


 

public class SmsCatcher extends Service{

BroadcastReceiver myBroadcast = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

        Log.i("myBroadcast SmsCatcher", "Entered onReceive method");
        if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
            Log.i("myBroadcast SmsCatcher", "Caught SCREEN_OFF");
        }
        if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
            Log.i("myBroadcast SmsCatcher", "Caught SCREEN_ON");
        }

        if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
            Log.i("myBroadcast SmsCatcher", "SMS_RECEIVED");
        }
    }
};

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
    Log.i("neil SmsCatcher", "Entered onCreate() in 'SmsCatcher extends Service'");
    Toast.makeText(this, "Entered onCreate() in 'SmsCatcher extends Service'", Toast.LENGTH_LONG).show();

    registerReceiver(myBroadcast, new IntentFilter(Intent.ACTION_SCREEN_ON));
    registerReceiver(myBroadcast, new IntentFilter(Intent.ACTION_SCREEN_OFF));

}

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

    Log.i("neil SmsCatcher", "Entered onDestroy() in 'SmsCatcher extends Service'");
    Toast.makeText(this, "Entered onDestroy() in 'SmsCatcher extends Service'", Toast.LENGTH_LONG).show();
}


}

UPDATE 1:
    
       我使用的 Internal Broadcasts Monitor to 去监听短信接收时的广播,看不到任何广告信息
UPDATE 2: FOUND PROBLEM BUT DONT KNOW HOW TO SOLVE I uninstalled the Google Hangouts (replaces Talk) app and it WORKS!!! Any solution around this? (should i be opening a separate thread as per stackoverflow rules?)
         我安装了 the Google Hangouts (replaces Talk) app ,居然能够工作!!程序可以捕获。。

 


 


原文地址:http://www.itmmd.com/201411/147.html
该文章由 萌萌的IT人 整理发布,转载须标明出处。

div 内部的div不能撑开父div的解决方法   上一篇
下一篇  android开发如何获得intent过滤 MimeType的内容

精彩回复
发表评论
姓名:       

《程序员app》专门为程序员量身定做!