gpt4 book ai didi

android - 通知声音不适用于 api 10 android

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:46:13 26 4
gpt4 key购买 nike

我使用这个函数来显示状态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);

关于android - 通知声音不适用于 api 10 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34174963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com