问题是:我定义一个广播,接收发送来的短信。但是,当我退出我的应用时,我的代码不能接收短信哦,怎么样才能让程序可以接收信息哦?代码如下:.MyStartB是我自定义的广播  <receiver android:name=".MyStartB" >             
            <intent-filter android:priority="1000">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                   <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>广播MyStartBpublic class MyStartB extends BroadcastReceiver {
 static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";@Override
 public void onReceive(Context context, Intent intent) {
  Log.e("TAG", "*****onReceive01******************");
  if (intent.getAction().equals(MyStartB.ACTION)) {
   Log.e("TAG", "*****onReceive02******************");}}//运行之后,没有输出结果哦,请大家帮我看看,怎么为事哦。可能是我没有发送广播。//我要发送广播得在activity里,但是我退出程序之后,activity也退出了,那么就不能//接收广播了吗?怎么样,让程序可以接收信息广播

解决方案 »

  1.   

    我用的模拟器,运行之后,没有反应!不管开机,还是发送短信, Log语句都不会输出!
      

  2.   

    把broascastreveiver设置成全局的,就是把它声明在manifest中。
      

  3.   


     <receiver android:name=".MyStartB"  android:enabled="true" >
                       
                <intent-filter android:priority="1000">
                    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                       <action android:name="android.intent.action.BOOT_COMPLETED" />
                </intent-filter>
            </receiver>一样,运行没有反应哦,log不输出哦···
      

  4.   

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