Katerina
Katerina

Reputation: 187

android local notifications once a week

I am trying to implement local notifications on an android application that I am building. What I want to do is to have a local notification once a week, and when the user presses the notification then a new activity will appear with the actual notification text.

I tried the tutorial below but with no luck: http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/

the notifications is not repeating every week and when i press it the first time that it appears, then it does not open the new activity.

Anyone who can give me a better tutorial or a good solution?

Upvotes: 0

Views: 781

Answers (1)

user4009281
user4009281

Reputation:

I don't know exactly how to set up your weekly notifications but i know how to start Activity when user click on Notification and clear the notification list after it:

There is declaration of Notification manager, and notification builder:

   NotificationManager notificationManager = (NotificationManager)
    Context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
    notificationBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    Uri alarmSound = RingtoneManager.getDefaultUri(R.raw.ok);
    notificationBuilder.setSound(alarmSound);

//There is declaration which Activity will be opened if user click on notification:

   Intent notificationIntent = new Intent(context, Notifications.class);
   //clear notification after clicking on it:
   notificationBuilder.setAutoCancel(true);
   PendingIntent newIntent = PendingIntent.getActivity(context, 0,notificationIntent, 0);
   notificationBuilder.setContentIntent(newIntent);
   notificationBuilder.setSmallIcon(R.drawable.ic_launcher).setContentTitle("APP    TITLE").setContentText("New notification");
   notificationManager.notify(001, notificationBuilder.build());

I hope this will help you!

Upvotes: 1

Related Questions