You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android12+Expo SDK47环境下Notifications.requestPermissionsAsync()不弹出授权提示求助

解决Android 12 + Expo SDK 47下Notifications.requestPermissionsAsync()不弹出授权提示的问题
  • 补充Android 12专属通知权限
    Android 12开始将通知权限从基础权限中拆分,Expo SDK 47不会默认添加POST_NOTIFICATIONS权限,需要手动在app.json里配置:

    {
      "expo": {
        "android": {
          "permissions": ["POST_NOTIFICATIONS"]
        }
      }
    }
    
  • 绑定权限请求到用户交互事件
    Android 12禁止应用冷启动时自动触发通知权限请求,必须将请求逻辑绑定到用户主动操作(比如按钮点击),示例代码:

    import * as Notifications from 'expo-notifications';
    import { Button } from 'react-native';
    
    const requestNotifyPerm = async () => {
      const { status } = await Notifications.requestPermissionsAsync();
      console.log('权限状态:', status);
    };
    
    // 在组件中渲染触发按钮
    <Button title="开启通知提醒" onPress={requestNotifyPerm} />
    
  • 确保通知模块完成初始化
    在项目入口文件(如App.js)中添加通知处理初始化逻辑,保证模块正常运行:

    import * as Notifications from 'expo-notifications';
    
    Notifications.setNotificationHandler({
      handleNotification: async () => ({
        shouldShowAlert: true,
        shouldPlaySound: false,
        shouldSetBadge: false,
      }),
    });
    
  • 清除缓存或重新构建项目
    如果之前用户拒绝过权限,或项目缓存存在异常,Android系统可能不再弹出提示。可通过系统设置清除应用数据,或执行expo prebuild --clean后重新构建测试。

  • 排查系统级权限限制
    检查设备是否全局禁用了该应用的通知权限,或省电模式、第三方权限拦截工具是否阻止了权限请求弹窗。

内容的提问来源于stack exchange,提问作者Muhammad Faisal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 20:55:19