Android EXPO sdk39中的应用程序通知设置访问权限

Android EXPO sdk39中的应用程序通知设置访问权限,android,react-native,notifications,expo,settings,Android,React Native,Notifications,Expo,Settings,当我意识到Permissions.askAsync无法按预期工作时,问题开始出现 我发现这是一个很酷的ios解决方案,但我需要android!因此,我为此添加了一些额外的代码: Alert.alert( 'No Notification Permission', 'please go to settings and enable notifications permissions manually', [ { text: 'ca

当我意识到Permissions.askAsync无法按预期工作时,问题开始出现

我发现这是一个很酷的ios解决方案,但我需要android!因此,我为此添加了一些额外的代码:

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。下面的结构非常好,但我想直接访问应用程序通知设置

onPress={() => {
            IntentLauncher.startActivityAsync(
              IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
              {
                data: `package:${Application.applicationId}`,
              }
            );
          }}
世博论坛相关问题

我尝试访问应用程序通知设置,但由于某些原因,我遇到了错误,如“在已安装的应用程序列表中找不到该应用程序”。在已发布的项目和单机版(apk)上进行了尝试,得到了相同的结果。有人知道问题出在哪里吗?

解决方案:

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:');
              }
            },
解决方案说明:

解决方案:

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:');
              }
            },

解决方案说明:

我意识到这有点晚了,但建议的答案对我不起作用。这就是使用Android版本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:这里的关键更改是
android.provider.extra.APP\u包作为
extra
键名。

我意识到这有点晚了,但建议的答案对我不起作用。这就是使用Android版本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:这里的关键更改是
android.provider.extra.APP\u包
作为
extra
键名