o android notification sound is not playing

General Tech Bugs & Fixes 2 years ago

2 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 30 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

This is my code for making notification and notification is showing but not playing sound please help me to identify mistakes in my code and do we need any permission to play sound,vibrate for notification?

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";

            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
            Notification notification = new Notification.Builder(MainActivity.this)
                    .setContentTitle("New Message")
                    .setContentText("You've received new messages. "+ct)
                    .setSmallIcon(R.drawable.ic_app_icon)
                    .setChannelId(CHANNEL_ID)   .setTicker("Showing button notification") //
                    .addAction(android.R.drawable.ic_dialog_alert
                                                
                                                
2 views
0 shares
profilepic.png
manpreet 2 years ago
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
                                                    
                                                    
2 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community