-
-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(share_plus): return correct share result on android (#1301)
- Loading branch information
Showing
6 changed files
with
62 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...re_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/SharePlusPendingIntent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dev.fluttercommunity.plus.share | ||
|
||
import android.content.* | ||
import android.os.Build | ||
|
||
/** | ||
* This helper class allows us to use FLAG_MUTABLE on the PendingIntent used in the Share class, | ||
* as it allows us to make the underlying Intent explicit, therefore avoiding any risks an implicit | ||
* mutable Intent may carry. | ||
* | ||
* When the PendingIntent is sent, the system will instantiate this class and call `onReceive` on it. | ||
*/ | ||
internal class SharePlusPendingIntent: BroadcastReceiver() { | ||
companion object { | ||
/** | ||
* Static member to access the result of the system instantiated instance | ||
*/ | ||
var result: String = "" | ||
} | ||
|
||
/** | ||
* Handler called after an action was chosen. Called only on success. | ||
*/ | ||
override fun onReceive(context: Context, intent: Intent) { | ||
// Extract chosen ComponentName | ||
val chosenComponent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
// Only available from API level 33 onwards | ||
intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT, ComponentName::class.java) | ||
} else { | ||
// Deprecated in API level 33 | ||
intent.getParcelableExtra<ComponentName>(Intent.EXTRA_CHOSEN_COMPONENT) | ||
} | ||
|
||
// Unambiguously identify the chosen action | ||
if (chosenComponent != null) { | ||
result = chosenComponent.flattenToString() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
packages/share_plus/share_plus/android/src/main/res/xml/flutter_share_file_paths.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<paths> | ||
<cache-path name="cache" path="share_plus/" /> | ||
<paths xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<!-- Used in conjunction with the provider declared in AndroidManifest.xml --> | ||
<cache-path name="cache" path="share_plus/" /> | ||
</paths> |