【发布时间】:2016-12-27 10:38:50
【问题描述】:
我正在尝试开发一个 android 应用程序,并在其中实现聊天功能。 但是当我收到消息时,它会发出通知声。 当用户以编程方式使用应用程序时,如何停止通知?
private void ChatNotifications(String uid, String fuid, String message) {
NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle();
notiStyle.setBigContentTitle("message");
// notiStyle.setSummaryText(quote);
notiStyle.bigText(message);
Intent resultIntent = new Intent(this, Loading.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(Loading.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
//Uri defaultSoundUri1 = Uri.parse("android.resource://com.therevew.quotes/" + R.raw.hello);
Uri defaultSoundUri1= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Notification myNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
// .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ii_launcher))
.setSound(defaultSoundUri1)
.setAutoCancel(true)
.setColor(getResources().getColor(R.color.notificationColor))
.setContentIntent(resultPendingIntent)
.setContentTitle("message")
.setContentText(message)
.setStyle(notiStyle).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(101/* ID of notification */, notiStyle.build());
}
【问题讨论】:
-
在发布问题之前,请在互联网上进行一些研究或上一个关于 SO 的问题。
标签: android android-studio push-notification google-cloud-messaging chat