MadaShindeInai
MadaShindeInai

Reputation: 590

App notification setting access in EXPO sdk39

Problem started when i realize that Permissions.askAsync not working as expected.

I find Permissions.askAsync not working as expected and it`s cool solution for ios, but i need it for android! So, i add some extra code for this:

Alert.alert(
        'No Notification Permission',
        'please go to settings and enable notifications permissions manually',
        [
          { text: 'cancel', onPress: () => console.log('cancel') },
          {
            text: 'Allow',
            onPress: async () => {
              if (Platform.OS === 'android') {
                await IntentLauncher.startActivityAsync(
                  IntentLauncher.ACTION_APP_NOTIFICATION_SETTINGS,
                  {
                    data: `package:${Application.applicationId}`,
                  }
                );
              }
              if (Platform.OS === 'ios') {
                Linking.openURL('app-settings:');
              }
            },
          },
        ],
        { cancelable: false },
      );

UPD. construction below works great, but i want to access directly to the APP_NOTIFICATION_SETTINGS.

onPress={() => {
            IntentLauncher.startActivityAsync(
              IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
              {
                data: `package:${Application.applicationId}`,
              }
            );
          }}

Related issue in expo forums https://forums.expo.io/t/opening-device-settings-on-android-using-linking/2059/14

I try to access to the APP_NOTIFICATION_SETTINGS but for some reason i'm getting error like "The app wasn't found in the list of installed apps". Tried it on published project and on standalone (apk) and got the same result. Anyone knows what is the problem?

Upvotes: 1

Views: 1814

Answers (3)

NorseGaud
NorseGaud

Reputation: 771

On modern Expo:

import * as Application from 'expo-application';
import * as IntentLauncher from 'expo-intent-launcher';
if (Platform.OS === 'ios') {
    Linking.openURL(`app-settings:`);
} else {
    await IntentLauncher.startActivityAsync(
        IntentLauncher.ActivityAction.APP_NOTIFICATION_SETTINGS,
        { extra: { 'android.provider.extra.APP_PACKAGE': Application.applicationId } }
    )
}

Upvotes: 0

fractaltheory
fractaltheory

Reputation: 56

I realize this is a bit late, but the suggested answer didn't work for me. This is what worked on my device using Android Version 29:

const pkg = Constants.manifest.releaseChannel
    ? Constants.manifest.android.package
    : 'host.exp.exponent';

IntentLauncher.startActivityAsync(
    IntentLauncher.ACTION_APP_NOTIFICATION_SETTINGS,
    {
        extra: { 'android.provider.extra.APP_PACKAGE': pkg }
    },
);

TL;DR: The key change here being android.provider.extra.APP_PACKAGE as the extra key name.

Upvotes: 4

MadaShindeInai
MadaShindeInai

Reputation: 590

Solution:

const pkg = Constants.manifest.releaseChannel
        ? Constants.manifest.android.package // When published, considered as using standalone build
        : 'host.exp.exponent'; // In expo client mode

onPress: () => {
              if (Platform.OS === 'android') {
                if (Platform.Version >= 26) {
                  IntentLauncher.startActivityAsync(
                    IntentLauncher.ACTION_APP_NOTIFICATION_SETTINGS,
                    {
                      data: `package:${pkg}`,
                    },
                  );
                } else {
                  IntentLauncher.startActivityAsync(
                    IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
                    {
                      data: `package:${pkg}`,
                    },
                  );
                }
              }
              if (Platform.OS === 'ios') {
                Linking.openURL('app-settings:');
              }
            },

Solution description: https://forums.expo.io/t/api-to-open-app-settings/5290/18

Upvotes: 0

Related Questions