I have got this simple code that issues a Notification.
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this)
.setSmallIcon(
R.drawable.ic_launcher)
.setContentTitle("Error deactivating Tracker")
.setContentText("Unable to send deactivation SMS");
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(0, mBuilder.build());
The notifications shows correctly on a 4.4.2 device, but it does not show on a 2.3.6 device.
I am using the NotificationCompat so I suppose it should show.
What am I doing wrong?
Solved.
Apparently it wants a PendingIntent in any case,
so I added it:
PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this)
.setSmallIcon(
R.drawable.ic_launcher)
.setContentTitle("Error deactivating Tracker")
.setContentText("Unable to send deactivation SMS")
.setContentIntent(pi).setTicker("Error deactivating Tracker");
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(0, mBuilder.build());
Related
Notification work normally one problem is All notification go to last notification link. How can I fix it? Every notification go to it's own link. Every message notification go to he's/she's inbox. How can I do that?
Intent intent_activity_start = new Intent(this,MainActivity.class);
intent_activity_start.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent_activity_start.putExtra("links", c.getString("link"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent_activity_start,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.logo);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
builder.setLargeIcon(getCircleBitmap(photoStream(c.getString("profile_photo"))));
builder.setContentTitle("Title");
builder.setContentText(c.getString("notify"));
builder.setSound(notificationSound);
builder.setStyle(new NotificationCompat.BigTextStyle()
.bigText(c.getString("notify")));
if(!c.getString("photo").equals("null")){
builder.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(photoStream(c.getString("photo"))));
}
NotificationManager notificationManager = (NotificationManager) getSystemService(
NOTIFICATION_SERVICE);
notificationManager.notify(counter.incrementAndGet(), builder.build());
I am getting push notification on Android phone on given model number but when I clicked on the notification, It disappear and doesn't open app. I would be grateful If anyone get me out from that problems.
Try Following Code May be work for you .
Intent intent = new Intent(this, MainActivity.class); //define your application activity name which you want to open.
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Application Title")
.setContentText(message)
.setContentIntent(pIntent)
.setSound(soundUri); //This sets the sound to play
notificationManager.notify(0, mBuilder.build());
I am making an application that uses notification in it but when the notification is about to appear this message is appearing continuously till i turn of the AVD "Unfortunately , System UI has stopped"
Intent viewIntent = new Intent(getBaseContext(), WorkshopActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getBaseContext())
.setSmallIcon(R.drawable.web)
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText("Scheduled")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent).setTicker("Compass");
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
notificationBuilder.setStyle(inboxStyle);
notificationBuilder.setStyle(inboxStyle);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int NOTIFICATION_ID = 100;
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
can you please replace getBaseContext() with 'this' or at least getApplicationContext() because BaseContent has a very rare & spesific usage.
and
.setContentIntent(pendingIntent).setTicker("Compass");
after this can you build the notificationBuilder,
.setContentIntent(pendingIntent).setTicker("Compass").build();
maybe it needs to build before adding style and addign it to manager.
lastly,
notificationManager.notify(NOTIFICATION_ID, notificationBuilder);
i have this code
NotificationCompat.Builder mBuilder= new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("Ticker")
.setContentTitle(getResources().getString(R.string.app_name))
.setAutoCancel(true)
.setContentText("Text")
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this,myActivity.class), 0));
NotificationManager notificationManager= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, mBuilder.build());
i run this code on htc one mini with android 4.3 and it is working correctly
but when i run this code on nexus 5(android:4.4.2 runtime:art) and when i clicked on the notification myActivity didn't start and only remove my notification(AutoCancle)
any ideas?thanks in advance
Try this :
private void addNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
String appname = context.getResources().getString(R.string.app_name);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification;
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, myactivity.class), 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(appname).setWhen(0)
.setAutoCancel(true).setContentTitle(appname)
.setContentText(message).build();
notificationManager.notify(0 , notification);
}
You need to pass current Context for creating mBuilder object.
Also, please run your app in "Dalvik Virtual machine(DVM)" instead of "Android Run time(ART)".
Check this link : https://source.android.com/devices/tech/dalvik/art.html
Note : Dalvik must remain the default runtime or you risk breaking your Android implementations and third-party applications.
Hope this helps.
In my notification, i want the led to blink in white color.
I am using NotificationCompat class from the support library to build the notification.
Notification fires up nicely, but led doesn't blink. (tested on Nexus 4)
Here's the code:
// Build notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.drawable.ic_stat_notify);
mBuilder.setTicker(getResources().getString(R.string.task_due));
mBuilder.setContentTitle(notify_title).setContentText(notify_descrip);
mBuilder.setDeleteIntent(deleteIntent());
mBuilder.setPriority(Notification.PRIORITY_DEFAULT);
mBuilder.setLights(0xFFFF0000, 500, 500);
mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
// On notification tap
Intent resultIntent = new Intent(this, SpecialActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
// Notify the user
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());