第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

o 安卓通知聲音不播放

o 安卓通知聲音不播放

呼喚遠(yuǎn)方 2022-09-22 19:29:57
這是我的代碼,用于制作通知和通知顯示但不播放聲音,請(qǐng)幫助我識(shí)別代碼中的錯(cuò)誤,我們是否需要任何權(quán)限來播放聲音,振動(dòng)通知?Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);            AudioAttributes attributes = new AudioAttributes.Builder()                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)                    .build();            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);            String id = "my_channel_01";            CharSequence name = "oreiomilla";            String description ="i love me";            int importance = NotificationManager.IMPORTANCE_HIGH;             NotificationChannel mChannel = new NotificationChannel(id, name, importance);             mChannel.setDescription(description);             mChannel.enableLights(true);             mChannel.setLightColor(Color.RED);            mChannel .setSound(alarmSound,attributes);            mChannel.enableVibration(true);            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});             mNotificationManager.createNotificationChannel(mChannel);             int notifyID = 1;             String CHANNEL_ID = "my_channel_01";
查看完整描述

2 回答

?
湖上湖

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊

要在 Oreo 中為通知設(shè)置聲音,必須在通知通道上設(shè)置聲音,而不是在通知生成器本身上設(shè)置聲音。您可以按如下方式執(zhí)行此操作


Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/" + R.raw.notification_mp3);


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {


        NotificationChannel mChannel = new NotificationChannel("YOUR_CHANNEL_ID",

            "YOUR CHANNEL NAME",

            NotificationManager.IMPORTANCE_DEFAULT)


        AudioAttributes attributes = new AudioAttributes.Builder()

                .setUsage(AudioAttributes.USAGE_NOTIFICATION)

                .build();


        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, 

                context.getString(R.string.app_name),

                NotificationManager.IMPORTANCE_HIGH);


        // Configure the notification channel.

        mChannel.setDescription(msg);

        mChannel.enableLights(true);

        mChannel.enableVibration(true);

        mChannel.setSound(sound, attributes); // This is IMPORTANT



        if (mNotificationManager != null)

            mNotificationManager.createNotificationChannel(mChannel);

    }


查看完整回答
反對(duì) 回復(fù) 2022-09-22
?
楊魅力

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊

試試這個(gè),它將為你工作。


private void BigTextNotificationForDays(Context context, String Message, String Author) {

            Intent resultIntent = new Intent(context, SplashActivity.class);

            resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

            PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) Calendar.getInstance().getTimeInMillis(), resultIntent, PendingIntent.FLAG_ONE_SHOT);


            //To set large icon in notification

            //  Bitmap icon1 = BitmapFactory.decodeResource(getResources(), R.drawable.big_image);


            //Assign inbox style notification

            NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();

            bigText.bigText(Message);

            bigText.setBigContentTitle(context.getString(R.string.app_name));

            bigText.setSummaryText(Author);

            //build notification

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context,createNotificationChannel(context))

                    .setSmallIcon(R.drawable.ic_notification)

                    .setContentTitle(context.getString(R.string.app_name))

                    .setContentText(Message)

                    .setStyle(bigText)

                    .setLargeIcon(icon)

                    .setColor(ContextCompat.getColor(context, R.color.colorPrimary))

                    .setVibrate(new long[]{1000, 1000})

                    .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)

                    .setPriority(Notification.PRIORITY_HIGH)

                    .setAutoCancel(true)

                    .setContentIntent(pendingIntent);

            //.setOngoing(true);


            // Gets an instance of the LocalNotificationManager service

            NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);


            //to post your notification to the notification bar

            mNotificationManager.notify(3730, mBuilder.build()); // (int) System.currentTimeMillis() set instead of id. if at a time more notification require

        }



public static String createNotificationChannel(Context context) {


        // NotificationChannels are required for Notifications on O (API 26) and above.

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {


            // The id of the channel.

            String channelId = "Channel_id";


            // The user-visible name of the channel.

            CharSequence channelName = "Application_name";

            // The user-visible description of the channel.

            String channelDescription = "Application_name Alert";

            int channelImportance = NotificationManager.IMPORTANCE_DEFAULT;

            boolean channelEnableVibrate = true;

//            int channelLockscreenVisibility = Notification.;


            // Initializes NotificationChannel.

            NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, channelImportance);

            notificationChannel.setDescription(channelDescription);

            notificationChannel.enableVibration(channelEnableVibrate);

//            notificationChannel.setLockscreenVisibility(channelLockscreenVisibility);


            // Adds NotificationChannel to system. Attempting to create an existing notification

            // channel with its original values performs no operation, so it's safe to perform the

            // below sequence.

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

            assert notificationManager != null;

            notificationManager.createNotificationChannel(notificationChannel);


            return channelId;

        } else {

            // Returns null for pre-O (26) devices.

            return null;

        }

    }


查看完整回答
反對(duì) 回復(fù) 2022-09-22
  • 2 回答
  • 0 關(guān)注
  • 131 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)