我使用这个函数来显示状态 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);
}
我设置了震动,但震动也没有起作用 :(
notification.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION););
。 - PankajNotificationCompat.Builder
- Pankaj