I set a daily alarm like this
public static void setDailyAlarm(Context context)
{
//Setting time for the alarm
Calendar calObject = Calendar.getInstance();
calObject.set(Calendar.HOUR_OF_DAY,hourOfRestart);
calObject.set(Calendar.MINUTE,minuteOfRestart);
//Initializing the Alarm Manager
AlarmManager m = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(MobileAgent.AGENTMGR_STOP);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent,PendingIntent.FLAG_CANCEL_CURRENT);
m.setRepeating(1,calObject.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi);
Log.i("appfwk_AgentMgrMonitor", "Daily Agent manager Restart Alarm set");
}
and then my pending intent is suppose to be received in another class like this
class MobileAgentReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Log.i("Mobile_agent", "INTENT RECIEVED");
if (intent != null) {
if (intent.getAction().equals(AGENTMGR_STOP)) {
Log.i("Mobile_agent", "agent manager stop issued");
}
}
}
}
This is a constructor of the class being initialized
public MobileAgent(Context context)
{
MobileAgentReceiver mobileAgentReceiver = new MobileAgentReceiver();
IntentFilter mobileAgentFilter = new IntentFilter(AGENTMGR_STOP);
LocalBroadcastManager.getInstance(context).registerReceiver(mobileAgentReceiver, mobileAgentFilter);
}
However the OnRecieve never receives the intent and never prints any of the logcat messages, I suspect its because I am using LocalBroadcast Manager, what can I use instead of that?
0 comments:
Post a Comment