android设置app全局没通知声,从android中的firebase发送通知时没有通知声音

试试这个....

public void buildPushNotification(Context ctx, String content, int icon, CharSequence text, boolean silent) {

Intent intent = new Intent(ctx, Activity.class);

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 1410, intent, PendingIntent.FLAG_ONE_SHOT);

Bitmap bm = BitmapFactory.decodeResource(ctx.getResources(), //large drawable);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(ctx)

.setSmallIcon(icon)

.setLargeIcon(bm)

.setContentTitle(content)

.setContentText(text)

.setAutoCancel(true)

.setContentIntent(pendingIntent);

if(!silent)

notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(1410, notificationBuilder.build());

}

并在onMessageReceived中调用它

@Override

public void onMessageReceived(RemoteMessage remoteMessage) {

Log.d("Msg", "Message received [" + remoteMessage.getNotification().getBody() + "]");

buildPushNotification(/*your param*/);

}

或者按照KongJing,他说也是正确的,但您可以使用Firebase控制台 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值