还有一个问题。试图使用广播接收器来触发警报(警报管理器)。
使用如下代码:package com.suncco.shangxinbao.service;
import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import com.suncco.shangxinbao.model.ScheduledSms;
public class SmsTimerService extends BroadcastReceiver {
public SmsTimerService(Context context, int timeoutInSeconds,
ScheduledSms sms) {
Intent myIntent = new Intent(context, SmsTimerService.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
sms.getRequestCodeForListener(), myIntent, 0);
AlarmManager alarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 5); // should be timeoutInSeconds instead of 5
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
pendingIntent);
}
@Override
public void onReceive(Context context, Intent intent) {
Log.w("Karl", "yay");
}
在清单中,我把它作为接收者:
<receiver
android:name="com.suncco.shangxinbao.service.SmsTimerService"
android:process=":remote" />
我像这样创建我的 SmsTimerService 对象:
SmsTimerService smsTimerService = new SmsTimerService(this,5,sms);
这是众所周知的错误......
java.lang.RuntimeException: Unable to instantiate receiver
com.suncco.shangxinbao.service.SmsTimerService: java.lang.InstantiationException:
com.suncco.shangxinbao.service.SmsTimerService