use of dev.sagar.smsblocker.tech.beans.Contact in project SMSBlocker by sagarpawardev.
the class NotificationUtilSingleton method createSMSNotification.
/**
* This Method Creates a Notification
* @param context
* @param sms
*/
public void createSMSNotification(Context context, SMS sms) {
final String methodName = "createSMSNotification()";
log.justEntered(methodName);
/*String fromNo = sms.getAddress();
String fromName = fromNo;
try {
fromName = ContactUtilSingleton.getInstance().getContactName(context, fromNo);
} catch (ReadContactPermissionException e) {
e.printStackTrace();
}
String text = sms.getBody();
String groupKey = fromNo;
int notificationId = getNotificationId();
log.info(methodName, "Creating Notification...");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notif)
.setContentTitle(fromName)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentText(text)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setGroup(groupKey)
.setStyle(new NotificationCompat.BigTextStyle().bigText(text))
.setWhen(sms.getDateTime())
.setShowWhen(true);
Intent resultIntent = new Intent(context, ThreadActivity.class);
Bundle bundle = new Bundle();
bundle.putString(ThreadActivity.KEY_ADDRESS, fromNo);
resultIntent.putExtras(bundle);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
context,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent)
.setAutoCancel(true);
NotificationManager mNotifyMgr =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyMgr.notify(notificationId, mBuilder.build());
log.info(methodName, "Notification Created with ID: "+notificationId);*/
/*generateSingleNotification(context, sms);
setSummaryNotification(context, sms);*/
int notifId = getNotificationId();
String address = sms.getAddress();
Contact contact = ContactUtilSingleton.getInstance().getContactOrDefault(context, address);
;
// -- Open Activity onClick Ends
Intent resultIntent = new Intent(context, ThreadActivity.class);
Bundle bundle = new Bundle();
bundle.putString(ThreadActivity.KEY_ADDRESS, address);
resultIntent.putExtras(bundle);
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// -- Open Activity onClick Ends
// Get Notification Builder
NotificationCompat.Builder mBuilder = getNotifBuilder(context, contact, sms);
NotificationCompat.Builder mGroupBuilder = getNotifBuilder(context, contact, sms).setGroupSummary(true);
NotificationCompat.Action action = getDirectReplyAction(context, sms, notifId);
// reply action from step b above
mBuilder.addAction(action);
mGroupBuilder.addAction(action);
// Set Priority
setPriority(context, mBuilder);
setPriority(context, mGroupBuilder);
// Group Notification
setGroup(context, mBuilder, contact);
setGroup(context, mGroupBuilder, contact);
// Setting on click envent
mBuilder.setContentIntent(resultPendingIntent).setAutoCancel(true);
mGroupBuilder.setContentIntent(resultPendingIntent).setAutoCancel(true);
log.info(methodName, "Creating Notification..");
NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);
Notification notification = mBuilder.build();
Notification notifGroupSummary = mGroupBuilder.build();
mNotificationManager.notify(notifId, notification);
mNotificationManager.notify(SUMMARY_ID, notifGroupSummary);
log.returning(methodName);
}
Aggregations