我的AndroidMainfest.xml中有两个BroadcastReceivers,
并为bll.BootNotificationReceiver设置<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
用于bll.SmsBroadcastReceiver。
所以我认为我不需要在ACTION.compareToIgnoreCase(intent.getAction()) == 0
中添加public void onReceive(Context context, Intent intent)
,对吗?
AndroidMainfest.xml
<!-- Broadcast receiver -->
<receiver android:name="bll.SmsBroadcastReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
SmsBroadcastReceiver.java
public class SmsBroadcastReceiver extends BroadcastReceiver{
private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null && ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
PublicPar.myContext=context;
}
}
}
BootNotificationReceiver.java
public class BootNotificationReceiver extends BroadcastReceiver{
private static final String ACTION = "android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent != null && intent.getAction() != null && ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
PublicPar.SetNotification();
}
}
}
答案 0 :(得分:0)
我认为以下代码就足够了。
public class SmsBroadcastReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null) {
PublicPar.myContext=context;
}
}
}
public class BootNotificationReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent != null && intent.getAction() != null) {
PublicPar.SetNotification();
}
}
}