Enable all notification settings by default in my android app
Asked Answered
D

3

12

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

Dortch answered 2/2, 2019 at 5:3 Comment(0)
T
4

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.

Thanks answered 17/4, 2021 at 11:35 Comment(1)
can i know where you get this information?Diseased
G
1

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

Granulose answered 31/5, 2019 at 11:18 Comment(1)
I need to add in my manifest file , then after the I am getting notificationHarmony
A
0

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

Accidie answered 2/2, 2019 at 8:44 Comment(2)
We are using React Native ... I think we need to find the code responsible for handling notifications and add code as you have suggested ... Will let you know if this works ! Thanks for the answer ! : )Dortch
@CaptainMAD Are you handled it in react native?Clammy

© 2022 - 2024 — McMap. All rights reserved.