通知声音停止点击
问题描述:
我使用以下代码添加通知,并在通知中添加了两个功能,一个是声音,另一个是闪烁的灯光。通知声音停止点击
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.cutomnotification);
contentView.setTextViewText(R.id.textView1,"Custom");
notification.contentView = contentView;
Intent notificationIntent = new Intent(v.getContext(), MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(v.getContext(), 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.sound=android.provider.Settings.System.DEFAULT_RINGTONE_URI;
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags=Notification.FLAG_INSISTENT|Notification.FLAG_SHOW_LIGHTS|Notification.FLAG_NO_CLEAR;
mNotificationManager.notify(HELLO_ID, notification);
在此我也使用了自定义布局,
现在我有两个问题,
1)的声音响起,当用户点击通知选项卡上它停了,但我想继续声音直到用户按下自定义布局上的任何按钮。
2)我在自定义布局中添加一个按钮,现在我可以在其上实现onClickListener()。
答
添加该代码后notification.contentIntent = contentIntent;
notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
notification.defaults |= Notification.DEFAULT_SOUND;
答
您可以创建NotificationCompat.Builder对象,而无需使用setSound()。这将创建一个没有任何声音的通知。
notification = mBuilder
.setStyle(notiStyle)
.setSmallIcon(notificationIcon)
.setTicker(title)
.setWhen(0)
.setAutoCancel(true)
.setContentTitle(title)
.setContentIntent(resultPendingIntent)
.build();
嘿有人在android中使用通知,请给我一些建议。 –
可以请任何人给我答案 –