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.
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);AudioAttributesattributes=newAudioAttributes.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 =newNotificationChannel(id, name, importance);
mChannel.setDescription(description);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel .setSound(alarmSound,attributes);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(newlong[]{100,200,300,400,500,400,300,200,400});
mNotificationManager.createNotificationChannel(mChannel);int notifyID =1;String CHANNEL_ID ="my_channel_01";Intent intent =newIntent(getApplicationContext(),MainActivity.class);PendingIntent pIntent =PendingIntent.getActivity(getApplicationContext(),0, intent,0);Notification notification =newNotification.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
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.
manpreet
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?