我用这个功能来显示状态notification
。一切正常,但没有声音播放notification
.
public void notifiction_main(String ticker,String title,String text,int _icon){
String ns = mContext.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(ns);
int icon = R.id.icon;
CharSequence tickerText = ticker; // ticker-text
long when = System.currentTimeMillis();
CharSequence contentTitle = title;
CharSequence contentText = text;
Intent notificationIntent = new Intent(mContext, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.setLatestEventInfo(mContext, contentTitle, contentText,contentIntent);
notification.defaults |= Notification.DEFAULT_VIBRATE;
mNotificationManager.notify(1, notification);
}
我在此之后设置了振动,但振动也不起作用:(
您可以使用NotificationCompat.Builder
NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
.setContentTitle("Title")
.setContentText("your_message")
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH);
notification.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
long[] pattern = {500,500,500,500};
notification.setVibrate(pattern);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)