I have implemented an AlarmManager that triggers and Alarm Receiver once
per day at 5 pm.
This worked fine, but I noticed that when I rebooted my phone, the alarm
never went off again. Is right? Should powering off cancel the nofication?
Intent launchIntent = new Intent(this, MyAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
launchIntent, 0);
AlarmManager alarmManager = (AlarmManager)
getSystemService(Context.ALARM_SERVICE);
long interval = 86400000; // the interval is one day
long firstTime = 0;
// create a Calendar object to set the real time at which the alarm
// should go off
Calendar alarmTime = Calendar.getInstance();
Calendar now = Calendar.getInstance();
alarmTime.setTimeInMillis(now.getTimeInMillis() + 10000);
firstTime = alarmTime.getTimeInMillis();
// Repeat every day at 5pm
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstTime, interval,
pendingIntent);
}
catch(Exception e){
}
So to fix I attempt to get the receiver to also go off when the phone
boots. I have the following in the manifest:
In my AndroidManifest.xml I have the following:
<receiver
android:name=".MyAlarmReceiver"
android:label="Notifications" >
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED" />
<action
android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE"
/>
<action android:name="android.intent.action.ALTERNATIVE" />
<category
android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
</receiver>
My receiver is not getting called after the phone boots, at least I don't
see the toast and the vibrate. Any ideas????
Finally, on my onReceive I want to do something that requires the network.
When my onReceive does get called after the phone boots, how do I make sure
the network is there before I proceed to hit the website I'm reading from.
Thanks!
public class MyAlarmReceiver extends BroadcastReceiver {
...
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Don't panik but your time is up!!!!.",
Toast.LENGTH_LONG).show();
// Vibrate the mobile phone
Vibrator vibrator = (Vibrator)
context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2000);
receivedContext = context;
getEvents();
}
};
pawpaw17
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.