I've created ~25 notifications.
Those notifications pop-up at the right times, but after a while they
pop-up randomly to.
I'm unsure why because I've programmed them to only go off at the times I
gave in:
Main activity code:
> //Alarm one
> private void Alarm(Context context) {
>
> Calendar updateTime = Calendar.getInstance();
> updateTime.set(Calendar.HOUR_OF_DAY, 8);
> updateTime.set(Calendar.MINUTE, 25);
> updateTime.set(Calendar.SECOND, 0);
> if(updateTime.before(new GregorianCalendar())){
> updateTime.add(GregorianCalendar.DAY_OF_MONTH, 1);
> }
> Intent intent = new Intent(context, AlarmReceiver1.class);
> intent.putExtra(ONE_TIME, Boolean.TRUE);
> PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent,
> 0);
> AlarmManager alarmManager = (AlarmManager)
> getSystemService(MyApp.ALARM_SERVICE);
> alarmManager.set(AlarmManager.RTC_WAKEUP,
> updateTime.getTimeInMillis(), pi);
> }
> AlarmReceiver1.class
> public class AlarmReceiver1 extends BroadcastReceiver {
>
> @Override
> public void onReceive(Context context, Intent intent) {
> Intent dailyUpdater = new Intent(context, MyAlarm1.class);
> context.startService(dailyUpdater);
> Log.d("MyApp BOT", "Alarm did go off..");
> }
>
> }
> MyAlarm1.class
>
> public class MyAlarm1 extends Service {
>
> private static final int NOTIFICATION_ID=2;
> private static final int REQUEST_CODE=1;
>
> public void displayNotification(String msg)
> {
> NotificationManager manager = (NotificationManager)
> getSystemService(Context.NOTIFICATION_SERVICE);
> Notification notification = new
> Notification(R.drawable.app_icon_v2, msg, System.currentTimeMillis());
> notification.defaults |= Notification.DEFAULT_LIGHTS;
> notification.flags |= Notification.FLAG_AUTO_CANCEL |
> Notification.FLAG_SHOW_LIGHTS;
>
> PendingIntent contentIntent = PendingIntent.getActivity(this,
> REQUEST_CODE, new Intent(this, ExpandNotification.class), 0);
>
> notification.setLatestEventInfo(this, "MyApp", "Notification
> one..", contentIntent);
>
> manager.notify(NOTIFICATION_ID, notification);
>
> }
>
> private NotificationManager mNM;
>
>
> private int NOTIFICATION = 546;
>
> public class LocalBinder extends Binder {
> MyAlarm1 getService() {
> return MyAlarm1.this;
> }
> }
>
> @Override
> public void onCreate() {
> mNM =
> (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
>
> showNotification();
> }
>
> @Override
> public int onStartCommand(Intent intent, int flags, int startId) {
> showNotification();
> return START_STICKY;
> }
>
> @Override
> public void onDestroy() {
> mNM.cancel(NOTIFICATION);
> //Toast.makeText(this, "stopped service",
> Toast.LENGTH_SHORT).show();
> }
>
> @Override
> public IBinder onBind(Intent intent) {
> return mBinder;
> }
>
> private final IBinder mBinder = new LocalBinder();
>
> private void showNotification() {
>
> //Ringtone..
> Uri notification =
> RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
> Ringtone r =
> RingtoneManager.getRingtone(getApplicationContext(), notification);
> r.play();
>
>
>
> displayNotification("MyApp Message..");
>
> // Vibrate patern
>
> // End of vibrate
>
>
>
> }
>
>
> }
ExpandNotification.class is an empty class file, not sure if I need it?
Why does my notification pops-up at the given times but also random after a
while ??
--
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