android local notifications once a week - android

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?

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!

Related

How to receive notification when the application is closed?

I'm making an android application, and I want to receive notifications when the application is closed, how can I do that? I've read also other posts where people ask it but i can't understand how to make it work, could you please try to explain this better?
I've also tried to make a countdownTimer and make the application do something when the timer reaches the 0 but it didn't work, 'cause obviusly when I close the application, I close the timer too.
use this code to make in app notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher) // notification icon
.setContentTitle("Notification!") // title for notification
.setContentText("Hello word") // message for notification
.setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());

NotificationCompat at a time

I want to show notification at defined time. I use "setWhen()". But any argument of setWhen() is ignoring and notification always showing instantly. What I did wrong? My code:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setWhen(???)
.setSmallIcon(R.drawable.app_icon)
.setContentTitle("Test")
.setContentText("Test");
Intent resultIntent = new Intent(this, MainActivity.class);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
That's not the purpose of setWhen. It's only a UI thing, if setShowWhen is enabled this timestamp is shown at the notification.
For your purpose, I would suggest the android AlarmManager. An example can be found here
setWhen() is used to show the time on the notification itself, not when the notification is shown.
The time on the top right of the notification is what setWhen() controls:
For showing the notification at a particular time, you can use the AlarmManager class. This has code to do the same.

How to disable multiple push Notification icon in Android, Am using Parse.com

com push notification for Android app, All is working well but lets say if i send 5 push notification a day, i dont want user to see 5 notification icons at once on his phone. Its best if he sees only one.So is their any way where old notification is deleted and only latest is shown.
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
The method that displays the notification has an int parameter which represents the notification identifier. If you use a constant identifier, each new notification will replace the previous one.
you have to set the notification ID to be the same value. So then they get replaced as each one arrives.
int notificationId = 1 ;
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.gcm_logo);
builder.setContentTitle("Test Title");
builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, builder.build());
So you can maintain notification Id for different type of notifications. If you keep same notification ID for each notification then it would be updated in the same .
If you have any extras in the pending intent and you want to update those extras with the latest ones then generate pending intent with :
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(),
PendingIntent.FLAG_ONE_SHOT);

regular notification wont show X close button in android

I created a notification using android.support.v4.app.NotificationCompat.Builder. The notification shows up fine in the notification area.But it doesn't show the default close button on android 4.2.
http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setOngoing(boolean)
As per the docuentation,its a type of regular notification which should show the X close button but it doesn't.
Using the following code:
mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(iconId);
mBuilder.setContentTitle(titleText);
mBuilder.setContentText(moreinfoText);
mBuilder.setOngoing(false); //to make it regular
PendingIntent pintent =
PendingIntent.getActivity(context,noteId,resultIntent,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pintent);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(noteId, mBuilder.build());
Searched on Google but couldn't find anything similar.
Please suggest.
Thanks for your time!

How do I keep my Android notification displayed until my app is closed?

I've been developing for Android for awhile but this is my first shot at notifications. I've got my notification setup as described in the Android SDK tutorial, but I can't figure out how to keep the notification displayed until my app is closed. I want to disable that little minus sign at the end of the notification. I don't want my notification to disappear when a user clicks it. I would think there would be a notification flag... but I can't seem to figure this out. I'm developing on Android SDK 2.2. I know this is a simple question, and I apologize if this answer is already on here... I wasn't able to find exactly what I was looking for.
// Create notification manager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Notification notification = new Notification(R.drawable.ic_launcher, "Ready", System.currentTimeMillis());
Intent notificationIntent = new Intent(this, HomeActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
// Make a notification
notification.setLatestEventInfo(getApplicationContext(), "Ready", "Select to manage your settings", contentIntent);
mNotificationManager.notify(0, notification);
You want FLAG_ONGOING_EVENT. Also try removing FLAG_NO_CLEAR and FLAG_AUTO_CANCEL if they are part of the defaults.

Categories

Resources