skip to Main Content

Is there any way I can enable all notification settings by default when my app gets installed ?

Users are receiving notifications but sound is disabled by default and we need to manually enable it on the device. Not all users can do this manually. It would be great to know if there is any way we can check all these things when our app gets installed like WhatsApp or Telegram (they have everything checked by default)

enter image description here

3

Answers


  1. Android 8 or higher you need to use NotificationChannel to enable sound, vibration, sound etc.

     Uri notification_sound  = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
    
    
            AudioAttributes attributes = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .build();
    
    
            notificationChannel.setSound(notification_sound, attributes);//for enable sound 
    
            notificationChannel.enableLights(true);
    
            notificationManager.createNotificationChannel(notificationChannel);
        }
    

    but in Redmi note 5 pro (MIUI 10.2.1.0) still notification sound is disabled. I think there is a bug in MIUI. Run this same code in mi A1(Android one mobile) everything fine. It works.

    refer this link to know more about Notification Channel

    Login or Signup to reply.
  2. Try using with this below permission in AndroidManifest file

    <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/>
    

    and set notification priority for both below and above Oreo versions IMPORTANCE_HIGH for Oreo and above, and PRIORITY_HIGH or PRIORITY_MAX for below Oreo versions

    Reference link for priority note

    Priority for version below Oreo

    mBuilder.setSmallIcon(R.drawable.app_logo)
                .setAutoCancel(true)
                .setContentIntent(resultPendingIntent)
                .setContentTitle(title)
                .setStyle(bigPictureStyle)
                .setSound(soundUri)
                .setPriority(NotificationCompat.PRIORITY_HIGH) // prirority here for version below Oreo
                .setWhen(System.currentTimeMillis())
                .setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.drawable.app_logo))
                .setContentText(message)
                .build();
    

    Priority for Oreo and above

    Refer this link

    Login or Signup to reply.
  3. WhatsApp, Telegram, Snapchat, and so on. These are all white-listed apps which means the package names are hardcoded at OS level to allow some of the permissions enabled by default. Our apps are not so. Hence, we need the user to enable those permissions manually.

    You can check this by yourself. Create a new android application give the package name of the Telegram application(org.telegram.messenger) and just run it. Don’t do any code at all, and no need to open the app too. Simply go to the notification settings of the newly created application, where you find all the permissions enabled by default.

    Hope you got the answer.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search