[@capacitor/share] "Can't share while sharing is in progress" when sharing to the same app on Android
还没有人认领这个 Issue。
评估
调研方向
从 Android SharePlugin 实现开始,跟踪 share()、activityResult()、isPresenting 和 handleOnNewIntent(),注意 MainActivity 如何为 ACTION_SEND 重用。使用链接的示例应用重现该问题,然后验证传入的 share 会重置进行中的状态,并且后续 share 能够成功。
由索引模型根据 Issue 内容生成。
描述
Bug Report
Plugin(s)
@capacitor/share
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 7.4.3
@capacitor/core: 7.4.3
@capacitor/android: 7.4.3
@capacitor/ios: 7.4.3
Installed Dependencies:
@capacitor/ios: not installed
@capacitor/cli: 7.4.3
@capacitor/core: 7.4.3
@capacitor/android: 7.4.3
[success] Android looking great! 👌
Platform(s)
Android
Current Behavior
In my app I have both outgoing + incoming share functionality. When I try to share anything to the same app, the plugin's Android implementation becomes stuck in some "in-progress" state, and subsequent share calls immediately fail with error:
Can't share while sharing is in progress
Expected Behavior
All subsequent shares from the app into same app work OK.
Code Reproduction
I've prepared reproduction repo - please check out https://github.com/dmitry-salnikov/capacitor-share-plugin-bug-reproduction
Other Technical Details
Android only, everything works OK on iOS.
Additional Context
The problem
- Android tries to launch
MainActivitywith theACTION_SEND intent. - Because
launchMode="singleTask", Android doesn't create a new activity instance. Instead, it reuses the existing task and brings it to the front. - Since the activity never finishes (it's the same instance),
activityResult()is never called. - This way,
isPresentingflag isn't reset, and all subsequent calls toshare()would throw errorCan't share while sharing is in progress.
The solution
Handle incoming share intent in SharePlugin's code to reset isPresenting flag and resolve plugin call, e.g.:
@Override
protected void handleOnNewIntent(Intent intent) {
if (isPresenting && intent != null && Intent.ACTION_SEND.equals(intent.getAction())) {
PluginCall call = bridge.getSavedCall("activityResult");
if (call != null) {
call.resolve(new JSObject().put("activityType", ""));
}
isPresenting = false;
}
}
- 主要语言
- Java
- 星标
- 682
- 派生
- 689
- 平均合并
- 5 天 11 小时
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ionic-team/capacitor-plugins 的其他 Issue
-
[@capacitor/app] iOS: 'Expression implicitly coerced from String? to Any' warning in getAppLanguage未关闭triage
难度 1/5 1 小时以内 新手友好度 88/100
ionic-team/capacitor-plugins#2604 ·
-
platform: ios
难度 4/5 3-5 天 新手友好度 58/100
ionic-team/capacitor-plugins#2603 · 1 条评论 ·
-
platform: android
难度 3/5 1-2 天 新手友好度 76/100
ionic-team/capacitor-plugins#2599 ·
-
platform: ios
难度 3/5 1-2 天 新手友好度 68/100
ionic-team/capacitor-plugins#2595 · 2 个 reaction ·
-
platform: android triage
难度 4/5 3-5 天 新手友好度 48/100
ionic-team/capacitor-plugins#2593 ·
查看 ionic-team/capacitor-plugins 的全部 Issue
相似的 Issue
-
area/frontend good first issue kind/cooldown
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
beehive-lab/TornadoVM#1151 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
FasterXML/jackson-dataformats-binary#823 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 1 天内回复