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

Android 14 PendingIntent后台启动Activity限制测试疑问

Android 14 Beta1中PendingIntent.send()后台启动Activity权限测试疑问

根据Android Developers文档,Android 14中应用调用PendingIntent#send()等方法发送PendingIntent时,若要通过该PendingIntent后台启动Activity,需携带配置了setPendingIntentBackgroundActivityStartMode(MODE_BACKGROUND_ACTIVITY_START_ALLOWED)的ActivityOptions bundle来启用权限。

我基于Android 14 Beta1、目标SDK为UpsideDownCake开展测试,存在疑问:我的测试流程是否正确?或是该限制尚未生效?

测试详情

  • 首次测试:将pendingIntent.send()置于按钮点击事件中,从当前应用后台向另一应用发送PendingIntent(未传入ActivityOptions),结果无论是否携带ActivityOptions bundle,均成功启动另一应用的Activity。
    代码示例:
    Intent intent = new Intent();
    intent.setClassName("another package name", "another class name"); 
    
    PendingIntent pendingIntent = PendingIntent.getActivity(
        getApplicationContext(), 2, intent, PendingIntent.FLAG_IMMUTABLE);
    pendingIntent.send();
    
  • 二次测试:仅创建一个应用,将pendingIntent.send()置于Service类中,同时在Service中创建了使用相机的ForegroundService,通过adb命令 adb shell am start-foreground-service -n [package-name]/[service-class-name] 启动Service,结果无论是否携带ActivityOptions bundle,均无法启动Activity,但ForegroundService可正常启动。

补充说明

我测试了Android Developers文档中关于bindService()启动Activity的限制,该限制已生效,因此推测PendingIntent.send()的限制也应生效,但实际测试结果不符。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 04:22:43