大佬教程收集整理的这篇文章主要介绍了Android推送通知声音仅在应用处于前景时播放,但在应用处于后台时不播放声音,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public void playNotificationSound() { try { Uri notification = @L_821_3@manager.getDefaultUri(@L_821_3@manager.TYPE_NOTIFICATION); ringtone r = @L_821_3@manager.getringtone(mCo@R_801_10443@t,notification); r.play(); } catch (Exception E) { e.printStackTrace(); } }
我正在调用这个OnmessageReceived方法,但声音仅在应用程序处于前台时播放,而不是在应用程序处于后台时播放
@Override public void onmessageReceived(Remotemessage remotemessagE) { Log.e@R_675_10374@,"From: " + remotemessage.getFrom()); if (remotemessage == null) return; // check if message contains a notification payload. if (remotemessage.getNotification() != null) { Log.e@R_675_10374@,"Notification Body: " + remotemessage.getNotification().getBody()); handleNotification(remotemessage.getNotification().getBody()); } // check if message contains a data payload. if (remotemessage.getData().size() > 0) { Log.e@R_675_10374@,"Data Payload: " + remotemessage.getData().toString()); try { JSONObject json = new JSONObject(remotemessage.getData().toString()); handleDatamessage(json); } catch (Exception E) { Log.e@R_675_10374@,"Exception: " + e.getmessage()); } } } private void handleNotification(String messagE) { if (!NotificationUtils.isAppIsInBACkground(getApplicationCo@R_801_10443@t())) { // app is in foreground,broadcast the push message Intent pushNotification = new Intent(con@L_262_12@.PUSH_NOTIFICATION); pushNotification.putExtra("message",messagE); LocalBroadcastManager.geTinstance(this).sendBroadcast(pushNotification); // play notification sound NotificationUtils notificationUtils = new NotificationUtils(getApplicationCo@R_801_10443@t()); notificationUtils.playNotificationSound(); }else if (NotificationUtils.isAppIsInBACkground(getApplicationCo@R_801_10443@t())){ // If the app is in BACkground,firebase itself handles the notification NotificationUtils notificationUtils = new NotificationUtils(getApplicationCo@R_801_10443@t()); notificationUtils.playNotificationSound(); } }
以上是大佬教程为你收集整理的Android推送通知声音仅在应用处于前景时播放,但在应用处于后台时不播放声音全部内容,希望文章能够帮你解决Android推送通知声音仅在应用处于前景时播放,但在应用处于后台时不播放声音所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。