diff --git a/packages/share_plus/share_plus/CHANGELOG.md b/packages/share_plus/share_plus/CHANGELOG.md index c50bf13632..ce449165c8 100644 --- a/packages/share_plus/share_plus/CHANGELOG.md +++ b/packages/share_plus/share_plus/CHANGELOG.md @@ -1,3 +1,9 @@ +## 4.0.2 + +- Fix type mismatch on Android for some users +- Set min Flutter to 1.20.0 for all platforms +- Lower Android minSdkVersion to 22 + ## 4.0.1 - Hotfix dependencies diff --git a/packages/share_plus/share_plus/android/build.gradle b/packages/share_plus/share_plus/android/build.gradle index 419619dc96..bc486e272c 100644 --- a/packages/share_plus/share_plus/android/build.gradle +++ b/packages/share_plus/share_plus/android/build.gradle @@ -28,7 +28,7 @@ android { compileSdkVersion 31 defaultConfig { - minSdkVersion 23 + minSdkVersion 22 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { diff --git a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/MethodCallHandler.kt b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/MethodCallHandler.kt index d44bcfac4c..775fed782c 100644 --- a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/MethodCallHandler.kt +++ b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/MethodCallHandler.kt @@ -5,71 +5,74 @@ import io.flutter.plugin.common.MethodChannel import java.io.IOException /** Handles the method calls for the plugin. */ -internal class MethodCallHandler(private val share: Share, private val manager: ShareSuccessManager) : MethodChannel.MethodCallHandler { +internal class MethodCallHandler( + private val share: Share, + private val manager: ShareSuccessManager +) : MethodChannel.MethodCallHandler { - override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { - when (call.method) { - "share" -> { - expectMapArguments(call) - // Android does not support showing the share sheet at a particular point on screen. - share.share( - call.argument("text") as String, - call.argument("subject") as String?, - false, - ) - result.success(null) - } - "shareFiles" -> { - expectMapArguments(call) + override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { + when (call.method) { + "share" -> { + expectMapArguments(call) + // Android does not support showing the share sheet at a particular point on screen. + share.share( + call.argument("text") as String, + call.argument("subject") as String?, + false, + ) + result.success(null) + } + "shareFiles" -> { + expectMapArguments(call) - // Android does not support showing the share sheet at a particular point on screen. - try { - share.shareFiles( - call.argument>("paths")!!, - call.argument?>("mimeTypes"), - call.argument("text"), - call.argument("subject"), - false, - ) - result.success(null) - } catch (e: IOException) { - result.error(e.message, null, null) - } - } - "shareWithResult" -> { - expectMapArguments(call) - if(!manager.setCallback(result)) return + // Android does not support showing the share sheet at a particular point on screen. + try { + share.shareFiles( + call.argument>("paths")!!, + call.argument?>("mimeTypes"), + call.argument("text"), + call.argument("subject"), + false, + ) + result.success(null) + } catch (e: IOException) { + result.error("Share failed", e.message, null) + } + } + "shareWithResult" -> { + expectMapArguments(call) + if (!manager.setCallback(result)) return - // Android does not support showing the share sheet at a particular point on screen. - share.share( - call.argument("text") as String, - call.argument("subject") as String?, - true, - ) - } - "shareFilesWithResult" -> { - expectMapArguments(call) - if(!manager.setCallback(result)) return + // Android does not support showing the share sheet at a particular point on screen. + share.share( + call.argument("text") as String, + call.argument("subject") as String?, + true, + ) + } + "shareFilesWithResult" -> { + expectMapArguments(call) + if (!manager.setCallback(result)) return - // Android does not support showing the share sheet at a particular point on screen. - try { - share.shareFiles( - call.argument>("paths")!!, - call.argument?>("mimeTypes"), - call.argument("text"), - call.argument("subject"), - true, - ) - } catch (e: IOException) { - result.error(e.message, null, null) + // Android does not support showing the share sheet at a particular point on screen. + try { + share.shareFiles( + call.argument>("paths")!!, + call.argument?>("mimeTypes"), + call.argument("text"), + call.argument("subject"), + true, + ) + } catch (e: IOException) { + result.error("Share failed", e.message, null) + } + } + else -> result.notImplemented() } - } - else -> result.notImplemented() } - } - @Throws(IllegalArgumentException::class) - private fun expectMapArguments(call: MethodCall) { - require(call.arguments is Map<*, *>) { "Map arguments expected" } - } + @Throws(IllegalArgumentException::class) + private fun expectMapArguments(call: MethodCall) { + require(call.arguments is Map<*, *>) { "Map arguments expected" } + } } diff --git a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt index 7804e32a58..e2c1d3248b 100644 --- a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt +++ b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt @@ -16,247 +16,241 @@ import java.io.IOException * intent. The `activity` might be null when constructing the [Share] object and set * to non-null when an activity is available using [.setActivity]. */ -internal class Share(private val context: Context, private var activity: Activity?, private val manager: ShareSuccessManager) { - private val providerAuthority: String by lazy { - getContext().packageName + ".flutter.share_provider" - } +internal class Share( + private val context: Context, + private var activity: Activity?, + private val manager: ShareSuccessManager +) { + private val providerAuthority: String by lazy { + getContext().packageName + ".flutter.share_provider" + } - private val shareCacheFolder: File - get() = File(getContext().cacheDir, "share_plus") + private val shareCacheFolder: File + get() = File(getContext().cacheDir, "share_plus") - - /** - * API v31+ requires `PendingIntent.FLAG_MUTABLE`, which is not available before - * v31. We therefore have to use different flag sets for pre- and post-API v31. - */ - private val pendingIntentFlags: Int by lazy { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE - } else { - PendingIntent.FLAG_UPDATE_CURRENT + /** + * Setting mutability flags as API v31+ requires. + */ + private val immutabilityIntentFlags: Int by lazy { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE + } else { + 0 + } } - } - private fun getContext(): Context { - if (activity != null) { - return activity!! - } - if (context != null) { - return context + private fun getContext(): Context { + return if (activity != null) { + activity!! + } else { + context + } } - throw IllegalStateException("Both context and activity are null") - } - /** - * Sets the activity when an activity is available. When the activity becomes unavailable, use - * this method to set it to null. - */ - fun setActivity(activity: Activity?) { - this.activity = activity - } - - fun share(text: String, subject: String?, withResult: Boolean) { - val shareIntent = Intent().apply { - action = Intent.ACTION_SEND - type = "text/plain" - putExtra(Intent.EXTRA_TEXT, text) - putExtra(Intent.EXTRA_SUBJECT, subject) - } - // If we dont want the result we use the old 'createChooser' - val chooserIntent = if (withResult) { - // Build chooserIntent with broadcast to ShareSuccessManager on success - Intent.createChooser( - shareIntent, - null, // dialog title optional - PendingIntent.getBroadcast( - context, - 0, - Intent(ShareSuccessManager.BROADCAST_CHANNEL), - pendingIntentFlags - ).getIntentSender() - ) - } else { - Intent.createChooser(shareIntent, null /* dialog title optional */) + /** + * Sets the activity when an activity is available. When the activity becomes unavailable, use + * this method to set it to null. + */ + fun setActivity(activity: Activity?) { + this.activity = activity } - startActivity(chooserIntent, withResult) - } - @Throws(IOException::class) - fun shareFiles( - paths: List, - mimeTypes: List?, - text: String?, - subject: String?, - withResult: Boolean - ) { - clearShareCacheFolder() - val fileUris = getUrisForPaths(paths) - val shareIntent = Intent() - when { - (fileUris.isEmpty() && !text.isNullOrBlank()) -> { - share(text, subject, withResult) - return - } - fileUris.size == 1 -> { - val mimeType = if (!mimeTypes.isNullOrEmpty()) { - mimeTypes.first() + fun share(text: String, subject: String?, withResult: Boolean) { + val shareIntent = Intent().apply { + action = Intent.ACTION_SEND + type = "text/plain" + putExtra(Intent.EXTRA_TEXT, text) + putExtra(Intent.EXTRA_SUBJECT, subject) + } + // If we dont want the result we use the old 'createChooser' + val chooserIntent = if (withResult) { + // Build chooserIntent with broadcast to ShareSuccessManager on success + Intent.createChooser( + shareIntent, + null, // dialog title optional + PendingIntent.getBroadcast( + context, + 0, + Intent(ShareSuccessManager.BROADCAST_CHANNEL), + PendingIntent.FLAG_UPDATE_CURRENT or immutabilityIntentFlags + ).intentSender + ) } else { - "*/*" + Intent.createChooser(shareIntent, null /* dialog title optional */) } - shareIntent.apply { - action = Intent.ACTION_SEND - type = mimeType - putExtra(Intent.EXTRA_STREAM, fileUris.first()) + startActivity(chooserIntent, withResult) + } + + @Throws(IOException::class) + fun shareFiles( + paths: List, + mimeTypes: List?, + text: String?, + subject: String?, + withResult: Boolean + ) { + clearShareCacheFolder() + val fileUris = getUrisForPaths(paths) + val shareIntent = Intent() + when { + (fileUris.isEmpty() && !text.isNullOrBlank()) -> { + share(text, subject, withResult) + return + } + fileUris.size == 1 -> { + val mimeType = if (!mimeTypes.isNullOrEmpty()) { + mimeTypes.first() + } else { + "*/*" + } + shareIntent.apply { + action = Intent.ACTION_SEND + type = mimeType + putExtra(Intent.EXTRA_STREAM, fileUris.first()) + } + } + else -> { + shareIntent.apply { + action = Intent.ACTION_SEND_MULTIPLE + type = reduceMimeTypes(mimeTypes) + putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris) + } + } } - } - else -> { - shareIntent.apply { - action = Intent.ACTION_SEND_MULTIPLE - type = reduceMimeTypes(mimeTypes) - putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris) + if (text != null) shareIntent.putExtra(Intent.EXTRA_TEXT, text) + if (subject != null) shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject) + shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + // If we dont want the result we use the old 'createChooser' + val chooserIntent = if (withResult) { + // Build chooserIntent with broadcast to ShareSuccessManager on success + Intent.createChooser( + shareIntent, + null, // dialog title optional + PendingIntent.getBroadcast( + context, + 0, + Intent(ShareSuccessManager.BROADCAST_CHANNEL), + PendingIntent.FLAG_UPDATE_CURRENT or immutabilityIntentFlags + ).intentSender + ) + } else { + Intent.createChooser(shareIntent, null /* dialog title optional */) } - } - } - if (text != null) shareIntent.putExtra(Intent.EXTRA_TEXT, text) - if (subject != null) shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject) - shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - // If we dont want the result we use the old 'createChooser' - val chooserIntent = if (withResult) { - // Build chooserIntent with broadcast to ShareSuccessManager on success - Intent.createChooser( - shareIntent, - null, // dialog title optional - PendingIntent.getBroadcast( - context, - 0, - Intent(ShareSuccessManager.BROADCAST_CHANNEL), - pendingIntentFlags - ).getIntentSender() - ) - } else { - Intent.createChooser(shareIntent, null /* dialog title optional */) - } - val resInfoList = getContext().packageManager.queryIntentActivities( - chooserIntent, PackageManager.MATCH_DEFAULT_ONLY - ) - resInfoList.forEach { resolveInfo -> - val packageName = resolveInfo.activityInfo.packageName - fileUris.forEach { fileUri -> - getContext().grantUriPermission( - packageName, - fileUri, - Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION, + val resInfoList = getContext().packageManager.queryIntentActivities( + chooserIntent, PackageManager.MATCH_DEFAULT_ONLY ) - } + resInfoList.forEach { resolveInfo -> + val packageName = resolveInfo.activityInfo.packageName + fileUris.forEach { fileUri -> + getContext().grantUriPermission( + packageName, + fileUri, + Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION, + ) + } + } + startActivity(chooserIntent, withResult) } - startActivity(chooserIntent, withResult) - } - private fun startActivity(intent: Intent, withResult: Boolean) { - when { - activity != null -> { - if (withResult) { - activity!!.startActivityForResult(intent, ShareSuccessManager.ACTIVITY_CODE) + private fun startActivity(intent: Intent, withResult: Boolean) { + if (activity != null) { + if (withResult) { + activity!!.startActivityForResult(intent, ShareSuccessManager.ACTIVITY_CODE) + } else { + activity!!.startActivity(intent) + } } else { - activity!!.startActivity(intent) - } - } - context != null -> { - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - if (withResult) { - // We need to cancel the callback to avoid deadlocking on the Dart side - manager.unavailable() + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + if (withResult) { + // We need to cancel the callback to avoid deadlocking on the Dart side + manager.unavailable() + } + context.startActivity(intent) } - context.startActivity(intent) - } - else -> { - throw IllegalStateException("Both context and activity are null") - } } - } - @Throws(IOException::class) - private fun getUrisForPaths(paths: List): ArrayList { - val uris = ArrayList(paths.size) - paths.forEach { path -> - var file = File(path) - if (fileIsInShareCache(file)) { - // If file is saved in '.../caches/share_plus' it will be erased by 'clearShareCacheFolder()' - throw IOException("Shared file can not be located in '${shareCacheFolder.canonicalPath}'") - } - file = copyToShareCacheFolder(file) - uris.add(FileProvider.getUriForFile(getContext(), providerAuthority, file)) + @Throws(IOException::class) + private fun getUrisForPaths(paths: List): ArrayList { + val uris = ArrayList(paths.size) + paths.forEach { path -> + var file = File(path) + if (fileIsInShareCache(file)) { + // If file is saved in '.../caches/share_plus' it will be erased by 'clearShareCacheFolder()' + throw IOException("Shared file can not be located in '${shareCacheFolder.canonicalPath}'") + } + file = copyToShareCacheFolder(file) + uris.add(FileProvider.getUriForFile(getContext(), providerAuthority, file)) + } + return uris } - return uris - } - /** - * Reduces provided MIME types to a common one to provide [Intent] with a correct type - * to share multiple files - */ - private fun reduceMimeTypes(mimeTypes: List?): String { - var reducedMimeType = "*/*" + /** + * Reduces provided MIME types to a common one to provide [Intent] with a correct type + * to share multiple files + */ + private fun reduceMimeTypes(mimeTypes: List?): String { + var reducedMimeType = "*/*" - mimeTypes?.let { types -> - { - if (types.size == 1) { - reducedMimeType = types.first() - } else if (types.size > 1) { - var commonMimeType = types.first() - for (i in 1..types.lastIndex) { - if (commonMimeType != types[i]) { - if (getMimeTypeBase(commonMimeType) == getMimeTypeBase(types[i])) { - commonMimeType = getMimeTypeBase(types[i]) + "/*" - } else { - commonMimeType = "*/*" - break - } + mimeTypes?.let { types -> + { + if (types.size == 1) { + reducedMimeType = types.first() + } else if (types.size > 1) { + var commonMimeType = types.first() + for (i in 1..types.lastIndex) { + if (commonMimeType != types[i]) { + if (getMimeTypeBase(commonMimeType) == getMimeTypeBase(types[i])) { + commonMimeType = getMimeTypeBase(types[i]) + "/*" + } else { + commonMimeType = "*/*" + break + } + } + } + reducedMimeType = commonMimeType + } } - } - reducedMimeType = commonMimeType } - } + return reducedMimeType } - return reducedMimeType - } - /** - * Returns the first part of provided MIME type, which comes before '/' symbol - */ - private fun getMimeTypeBase(mimeType: String?): String { - return if (mimeType == null || !mimeType.contains("/")) { - "*" - } else { - mimeType.substring(0, mimeType.indexOf("/")) + /** + * Returns the first part of provided MIME type, which comes before '/' symbol + */ + private fun getMimeTypeBase(mimeType: String?): String { + return if (mimeType == null || !mimeType.contains("/")) { + "*" + } else { + mimeType.substring(0, mimeType.indexOf("/")) + } } - } - private fun fileIsInShareCache(file: File): Boolean { - return try { - val filePath = file.canonicalPath - filePath.startsWith(shareCacheFolder.canonicalPath) - } catch (e: IOException) { - false + private fun fileIsInShareCache(file: File): Boolean { + return try { + val filePath = file.canonicalPath + filePath.startsWith(shareCacheFolder.canonicalPath) + } catch (e: IOException) { + false + } } - } - private fun clearShareCacheFolder() { - val folder = shareCacheFolder - val files = folder.listFiles() - if (folder.exists() && !files.isNullOrEmpty()) { - files.forEach { it.delete() } - folder.delete() + private fun clearShareCacheFolder() { + val folder = shareCacheFolder + val files = folder.listFiles() + if (folder.exists() && !files.isNullOrEmpty()) { + files.forEach { it.delete() } + folder.delete() + } } - } - @Throws(IOException::class) - private fun copyToShareCacheFolder(file: File): File { - val folder = shareCacheFolder - if (!folder.exists()) { - folder.mkdirs() + @Throws(IOException::class) + private fun copyToShareCacheFolder(file: File): File { + val folder = shareCacheFolder + if (!folder.exists()) { + folder.mkdirs() + } + val newFile = File(folder, file.name) + file.copyTo(newFile, true) + return newFile } - val newFile = File(folder, file.name) - file.copyTo(newFile, true) - return newFile - } } diff --git a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/SharePlusPlugin.kt b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/SharePlusPlugin.kt index 1657c6b183..b3b831ed10 100644 --- a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/SharePlusPlugin.kt +++ b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/SharePlusPlugin.kt @@ -8,42 +8,42 @@ import io.flutter.plugin.common.MethodChannel /** Plugin method host for presenting a share sheet via Intent */ class SharePlusPlugin : FlutterPlugin, ActivityAware { - private lateinit var share: Share - private lateinit var manager: ShareSuccessManager - private lateinit var methodChannel: MethodChannel - - override fun onAttachedToEngine(binding: FlutterPluginBinding) { - methodChannel = MethodChannel(binding.binaryMessenger, CHANNEL) - manager = ShareSuccessManager(binding.applicationContext) - manager.register() - share = Share(context = binding.applicationContext, activity = null, manager = manager) - val handler = MethodCallHandler(share, manager) - methodChannel.setMethodCallHandler(handler) - } - - override fun onDetachedFromEngine(binding: FlutterPluginBinding) { - manager.discard() - methodChannel.setMethodCallHandler(null) - } - - override fun onAttachedToActivity(binding: ActivityPluginBinding) { - binding.addActivityResultListener(manager) - share.setActivity(binding.activity) - } - - override fun onDetachedFromActivity() { - share.setActivity(null) - } - - override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { - onAttachedToActivity(binding) - } - - override fun onDetachedFromActivityForConfigChanges() { - onDetachedFromActivity() - } - - companion object { - private const val CHANNEL = "dev.fluttercommunity.plus/share" - } + private lateinit var share: Share + private lateinit var manager: ShareSuccessManager + private lateinit var methodChannel: MethodChannel + + override fun onAttachedToEngine(binding: FlutterPluginBinding) { + methodChannel = MethodChannel(binding.binaryMessenger, CHANNEL) + manager = ShareSuccessManager(binding.applicationContext) + manager.register() + share = Share(context = binding.applicationContext, activity = null, manager = manager) + val handler = MethodCallHandler(share, manager) + methodChannel.setMethodCallHandler(handler) + } + + override fun onDetachedFromEngine(binding: FlutterPluginBinding) { + manager.discard() + methodChannel.setMethodCallHandler(null) + } + + override fun onAttachedToActivity(binding: ActivityPluginBinding) { + binding.addActivityResultListener(manager) + share.setActivity(binding.activity) + } + + override fun onDetachedFromActivity() { + share.setActivity(null) + } + + override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { + onAttachedToActivity(binding) + } + + override fun onDetachedFromActivityForConfigChanges() { + onDetachedFromActivity() + } + + companion object { + private const val CHANNEL = "dev.fluttercommunity.plus/share" + } } diff --git a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/ShareSuccessManager.kt b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/ShareSuccessManager.kt index 690f9af8db..36e1a4c50e 100644 --- a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/ShareSuccessManager.kt +++ b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/ShareSuccessManager.kt @@ -1,10 +1,6 @@ package dev.fluttercommunity.plus.share -import android.content.ComponentName -import android.content.Context -import android.content.BroadcastReceiver -import android.content.Intent -import android.content.IntentFilter +import android.content.* import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.PluginRegistry.ActivityResultListener import java.util.concurrent.atomic.AtomicBoolean @@ -13,9 +9,10 @@ import java.util.concurrent.atomic.AtomicBoolean * Handles the callback based status information about a successful or dismissed * share. Used to link multiple different callbacks together for easier use. */ -internal class ShareSuccessManager(private val context: Context): BroadcastReceiver(), ActivityResultListener { +internal class ShareSuccessManager(private val context: Context) : BroadcastReceiver(), + ActivityResultListener { private var callback: MethodChannel.Result? = null - private var calledBack: AtomicBoolean = AtomicBoolean(true) + private var isCalledBack: AtomicBoolean = AtomicBoolean(true) /** * Register listener. Must be called before any share sheet is opened. @@ -36,13 +33,17 @@ internal class ShareSuccessManager(private val context: Context): BroadcastRecei * the componentname of the chosen option or an empty string on dismissal. */ fun setCallback(callback: MethodChannel.Result): Boolean { - if (calledBack.compareAndSet(true, false)) { - calledBack.set(false) + return if (isCalledBack.compareAndSet(true, false)) { + isCalledBack.set(false) this.callback = callback - return true; + true } else { - callback.error("prior share-sheet did not call back, did you await it? Maybe use non-result variant", null, null) - return false; + callback.error( + "Share callback error", + "prior share-sheet did not call back, did you await it? Maybe use non-result variant", + null, + ) + false } } @@ -57,30 +58,32 @@ internal class ShareSuccessManager(private val context: Context): BroadcastRecei * Send the result to flutter by invoking the previously set callback. */ private fun returnResult(result: String) { - if (calledBack.compareAndSet(false, true) && callback != null) { + if (isCalledBack.compareAndSet(false, true) && callback != null) { callback!!.success(result) callback = null } } /** - * Handler called after a sharesheet was closed. Called regardless of success or + * Handler called after a share sheet was closed. Called regardless of success or * dismissal. */ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean { - if (requestCode == ACTIVITY_CODE) { + return if (requestCode == ACTIVITY_CODE) { returnResult("") - return true + true + } else { + false } - - return false } /** * Handler called after a sharesheet was closed. Called only on success. */ override fun onReceive(context: Context, intent: Intent) { - returnResult(intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT).toString()) + returnResult( + intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT).toString() + ) } companion object { diff --git a/packages/share_plus/share_plus/example/android/app/build.gradle b/packages/share_plus/share_plus/example/android/app/build.gradle index c94d677982..d30aca2256 100644 --- a/packages/share_plus/share_plus/example/android/app/build.gradle +++ b/packages/share_plus/share_plus/example/android/app/build.gradle @@ -33,7 +33,7 @@ android { defaultConfig { applicationId "io.flutter.plugins.shareexample" - minSdkVersion 23 + minSdkVersion 22 targetSdkVersion 31 versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/packages/share_plus/share_plus/pubspec.yaml b/packages/share_plus/share_plus/pubspec.yaml index b65aa987a5..987288dd8f 100644 --- a/packages/share_plus/share_plus/pubspec.yaml +++ b/packages/share_plus/share_plus/pubspec.yaml @@ -1,6 +1,6 @@ name: share_plus description: Flutter plugin for sharing content via the platform share UI, using the ACTION_SEND intent on Android and UIActivityViewController on iOS. -version: 4.0.1 +version: 4.0.2 homepage: https://plus.fluttercommunity.dev/ repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ @@ -39,4 +39,4 @@ dev_dependencies: environment: sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.12.13+hotfix.5" + flutter: ">=1.20.0" diff --git a/packages/share_plus/share_plus_platform_interface/CHANGELOG.md b/packages/share_plus/share_plus_platform_interface/CHANGELOG.md index f4b9bad996..4d2df718d6 100644 --- a/packages/share_plus/share_plus_platform_interface/CHANGELOG.md +++ b/packages/share_plus/share_plus_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.1 + +- Set min Flutter to 1.20.0 to match Share plugins on all platforms + ## 3.0.0 - Add *WithResult methods to get feedback on user action diff --git a/packages/share_plus/share_plus_platform_interface/pubspec.yaml b/packages/share_plus/share_plus_platform_interface/pubspec.yaml index 2c691865a7..50ca67971b 100644 --- a/packages/share_plus/share_plus_platform_interface/pubspec.yaml +++ b/packages/share_plus/share_plus_platform_interface/pubspec.yaml @@ -1,6 +1,6 @@ name: share_plus_platform_interface description: A common platform interface for the share_plus plugin. -version: 3.0.0 +version: 3.0.1 homepage: https://plus.fluttercommunity.dev/ repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ @@ -20,4 +20,4 @@ dev_dependencies: environment: sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.12.13+hotfix.5" + flutter: ">=1.20.0"