ionic-team / ionic-team/capacitor-plugins
[@capacitor/share] "Can't share while sharing is in progress" when sharing to the same app on Android
- Dominant language
- Java
- Stars
- 678
- Forks
- 685
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 3
Description
## 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 `MainActivity` with the `ACTION_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, `isPresenting` flag isn't reset, and all subsequent calls to `share()` would throw error `Can'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.:
```java
@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;
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.