当我意识到Permissions.askAsync没有按预期工作时,问题就开始了。
我发现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。下面的构建效果很好,但我想直接访问APP_NOTIFICATION_SETTINGS。
onPress={() => {
IntentLauncher.startActivityAsync(
IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
{
data: `package:${Application.applicationId}`,
}
);
}}
世博论坛中的相关问题https://forums.expo.io/t/opening-device-settings-on-android-using-linking/2059/14
我试图访问APP_NOTIFICATION_SETTINGS,但由于某种原因,我遇到了类似"的错误;在已安装的应用程序列表中找不到该应用程序在已发布的项目和单机版(apk(上进行了尝试,得到了相同的结果。有人知道问题出在哪里吗?
我意识到这有点晚了,但建议的答案对我不起作用。这就是在我的设备上使用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_PACKAGE
作为extra
密钥名称。
解决方案:
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:');
}
},
解决方案描述:https://forums.expo.io/t/api-to-open-app-settings/5290/18