Мне нужно добавить уведомление BigTextStyle в мое приложение. У меня есть 3 кнопки, используя действие добавления свойства, и на каждой кнопке выполняется другое действие. Теперь проблема в том, что когда я нажимаю на любую из кнопок, уведомление не очищается. он все еще остается в области уведомлений. Может ли один помочь мне в этом .....Уведомление BigTextStyle
вот мой метод ....
private void fireTheNotificaiton(Context _notifyContext,
String message,
int notifiId,
ActionMessage msg) {
Notification noti = new Notification();
noti = setBigTextStyleNotification(_notifyContext,
message,
notifiId,
msg);
noti.defaults |= Notification.DEFAULT_LIGHTS;
noti.defaults |= Notification.DEFAULT_VIBRATE;
noti.defaults |= Notification.DEFAULT_SOUND;
noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
noti.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager nm = (NotificationManager) _notifyContext.getSystemService(
_notifyContext.NOTIFICATION_SERVICE);
nm.notify(notifiId, noti);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private Notification setBigTextStyleNotification(Context _notifyContext,
String message,
int notifiId,
ActionMessage msg) {
Bitmap icon = null;
NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle();
notiStyle.setBigContentTitle("Action:" + message);
String time = DateFormat.getTimeInstance().format(new Date()).toString();
notiStyle.setSummaryText(time);
try {
icon = BitmapFactory.decodeResource(getResources(),
R.drawable.truckfront);
} catch (Exception e) {
e.printStackTrace();
}
// Add the big text to the style.
CharSequence bigText = msg.getMessage();
notiStyle.bigText(bigText);
session.fromactionnotification(true);
// Creates an explicit intent for an ResultActivity to receive.
Intent intent1 = null;
{
intent1 = new Intent(getApplicationContext(), ActionTakenActivity.class);
intent1.putExtra("msg", msg);
}
intent1.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent intent = PendingIntent.getActivity(_notifyContext, 0, intent1,
PendingIntent.FLAG_UPDATE_CURRENT);
Intent intent2 = null;
{
intent2 = new Intent(getApplicationContext(), EmptyActivity.class);
intent2.putExtra("msg", msg);
intent2.putExtra("yes", 1);
}
intent2.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent intent21 = PendingIntent.getActivity(_notifyContext, 0, intent2,
PendingIntent.FLAG_UPDATE_CURRENT);
Intent intent3 = null;
{
intent3 = new Intent(getApplicationContext(), EmptyActivity.class);
intent3.putExtra("msg", msg);
intent3.putExtra("yes", 2);
}
intent3.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent intent31 = PendingIntent.getActivity(_notifyContext, 0, intent3,
PendingIntent.FLAG_UPDATE_CURRENT);
session.fromactionnotification(true);
return new NotificationCompat.Builder(_notifyContext)
.setSmallIcon(R.drawable.truckfront)
.setAutoCancel(true)
.setLargeIcon(icon)
.addAction(R.drawable.ic_visibility_black_24dp, "View", intent)
.addAction(R.drawable.ic_done_black_24dp, "Yes", intent21)
.addAction(R.drawable.ic_clear_black_24dp, "Can't", intent31)
.setContentTitle("Action:" + message)
.setContentText(msg.getMessage())
.setStyle(notiStyle).build();
}
он работает над деятельностью, но мой класс расширяет GcmListenerService, он не работает над этим. – srk
Это означает, что вы должны передать правильный контекст в классе, где вы делаете вызов 'cancelNotification()' метод – Apurva
вы имеете в виду я должен сделать это государственной статической силы cancelNotification (INT notificationId, контекст contextCancel) { nm.cancel (notificationId); } и на EmptyActivity или ActionTakenActivity NotificationHelper.cancelNotification (0, getApplicationContext()); – srk