先生,我真的不知道如何让我的代码工作。它只是无法启动警报。它只是启动分配的活动并跳过警报部分。我究竟做错了什么。提前感谢您的帮助
public class EAlarmReceiver extends BroadcastReceiver {
public static String sender;
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Bundle bundle = intent.getExtras();
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdusObj.length];
for (int i = 0; i<pdusObj.length; i++)
{
messages[i] = SmsMessage.createFromPdu ((byte[])
pdusObj[i]);
sender = messages[i].getOriginatingAddress();
}
for (SmsMessage msg : messages) {
if (msg.getMessageBody().contains("firealert")) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 0);
Intent i = new Intent(context, ReceiverInterface.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
12345, i, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am =
(AlarmManager)context.getSystemService(Activity.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
}//end if
}//end for
}// end onreceive