private void displayNotification(String Number, String messages) {
// TODO Auto-generated method stub
// Invoking the default notification service
mBuilder = new NotificationCompat.Builder(ctx);
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 400 milliseconds
v.vibrate(400);
String name=getContactName(ctx, Number);
mBuilder.setContentTitle(name);
mBuilder.setContentText(messages);
mBuilder.setTicker("New Message Received!");
mBuilder.setSmallIcon(R.drawable.ic_launcher);
// Increase notification number every time a new notification arrives
mBuilder.setNumber(++numMessagesOne);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(ctx, NavigationMain.class);
resultIntent.putExtra("notificationId", notificationIdOne);
//This ensures that navigating backward from the Activity leads out of the app to Home page
TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx);
// Adds the back stack for the Intent
stackBuilder.addParentStack(ChatActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_ONE_SHOT //can only be used once
);
// start the activity when the user clicks the notification text
mBuilder.setContentIntent(resultPendingIntent);
myNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
// pass the Notification object to the system
myNotificationManager.notify(notificationIdOne, mBuilder.build());
}
// TODO Auto-generated method stub
// Invoking the default notification service
mBuilder = new NotificationCompat.Builder(ctx);
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 400 milliseconds
v.vibrate(400);
String name=getContactName(ctx, Number);
mBuilder.setContentTitle(name);
mBuilder.setContentText(messages);
mBuilder.setTicker("New Message Received!");
mBuilder.setSmallIcon(R.drawable.ic_launcher);
// Increase notification number every time a new notification arrives
mBuilder.setNumber(++numMessagesOne);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(ctx, NavigationMain.class);
resultIntent.putExtra("notificationId", notificationIdOne);
//This ensures that navigating backward from the Activity leads out of the app to Home page
TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx);
// Adds the back stack for the Intent
stackBuilder.addParentStack(ChatActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_ONE_SHOT //can only be used once
);
// start the activity when the user clicks the notification text
mBuilder.setContentIntent(resultPendingIntent);
myNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
// pass the Notification object to the system
myNotificationManager.notify(notificationIdOne, mBuilder.build());
}
Comments
Post a Comment