“构造函数意图(EAlarmReceiver,Class)未定义”是什么意思?这是使用短信触发报警的正确方法,即使在静音模式下,我怎么还能启动报警?提前谢谢
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("alert")) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 1);
Intent i = new Intent(EAlarmReceiver.this, 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
答案 0 :(得分:1)
使用context
代替EAlarmReceiver.this
。
http://developer.android.com/reference/android/content/Intent.html#Intent(android.content.Context,java.lang.Class)