Skip to content

Commit

Permalink
build(share_plus): Update to target and compile SDK 34 on Android (#2712
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vbuberen committed Mar 17, 2024
1 parent fd48920 commit b752fc3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 57 deletions.
8 changes: 4 additions & 4 deletions packages/share_plus/share_plus/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 33
compileSdk 34

namespace 'dev.fluttercommunity.plus.share'

Expand All @@ -39,7 +39,7 @@ android {
}

defaultConfig {
minSdkVersion 19
minSdk 19
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand All @@ -49,7 +49,7 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.annotation:annotation:1.7.0'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.annotation:annotation:1.7.1'
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,22 @@ internal class Share(
}
}
// 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(context, SharePlusPendingIntent::class.java),
PendingIntent.FLAG_UPDATE_CURRENT or immutabilityIntentFlags
).intentSender
)
} else {
Intent.createChooser(shareIntent, null /* dialog title optional */)
}
val chooserIntent =
if (withResult && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
// Build chooserIntent with broadcast to ShareSuccessManager on success
Intent.createChooser(
shareIntent,
null, // dialog title optional
PendingIntent.getBroadcast(
context,
0,
Intent(context, SharePlusPendingIntent::class.java),
PendingIntent.FLAG_UPDATE_CURRENT or immutabilityIntentFlags
).intentSender
)
} else {
Intent.createChooser(shareIntent, null /* dialog title optional */)
}
startActivity(chooserIntent, withResult)
}

Expand All @@ -99,6 +100,7 @@ internal class Share(
share(text, subject, withResult)
return
}

fileUris.size == 1 -> {
val mimeType = if (!mimeTypes.isNullOrEmpty()) {
mimeTypes.first()
Expand All @@ -111,6 +113,7 @@ internal class Share(
putExtra(Intent.EXTRA_STREAM, fileUris.first())
}
}

else -> {
shareIntent.apply {
action = Intent.ACTION_SEND_MULTIPLE
Expand All @@ -123,21 +126,22 @@ internal class Share(
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(context, SharePlusPendingIntent::class.java),
PendingIntent.FLAG_UPDATE_CURRENT or immutabilityIntentFlags
).intentSender
)
} else {
Intent.createChooser(shareIntent, null /* dialog title optional */)
}
val chooserIntent =
if (withResult && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
// Build chooserIntent with broadcast to ShareSuccessManager on success
Intent.createChooser(
shareIntent,
null, // dialog title optional
PendingIntent.getBroadcast(
context,
0,
Intent(context, SharePlusPendingIntent::class.java),
PendingIntent.FLAG_UPDATE_CURRENT or immutabilityIntentFlags
).intentSender
)
} else {
Intent.createChooser(shareIntent, null /* dialog title optional */)
}
val resInfoList = getContext().packageManager.queryIntentActivities(
chooserIntent, PackageManager.MATCH_DEFAULT_ONLY
)
Expand Down Expand Up @@ -186,27 +190,27 @@ internal class Share(
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>?): String {
if (mimeTypes?.isEmpty() ?: true) return "*/*"
if (mimeTypes!!.size == 1) return mimeTypes.first()

var commonMimeType = mimeTypes.first()
for (i in 1..mimeTypes.lastIndex) {
if (commonMimeType != mimeTypes[i]) {
if (getMimeTypeBase(commonMimeType) == getMimeTypeBase(mimeTypes[i])) {
commonMimeType = getMimeTypeBase(mimeTypes[i]) + "/*"
} else {
commonMimeType = "*/*"
break
/**
* 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>?): String {
if (mimeTypes?.isEmpty() != false) return "*/*"
if (mimeTypes.size == 1) return mimeTypes.first()

var commonMimeType = mimeTypes.first()
for (i in 1..mimeTypes.lastIndex) {
if (commonMimeType != mimeTypes[i]) {
if (getMimeTypeBase(commonMimeType) == getMimeTypeBase(mimeTypes[i])) {
commonMimeType = getMimeTypeBase(mimeTypes[i]) + "/*"
} else {
commonMimeType = "*/*"
break
}
}
}
}
return commonMimeType
}
return commonMimeType
}

/**
* Returns the first part of provided MIME type, which comes before '/' symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal class SharePlusPendingIntent: BroadcastReceiver() {
intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT, ComponentName::class.java)
} else {
// Deprecated in API level 33
@Suppress("DEPRECATION")
intent.getParcelableExtra<ComponentName>(Intent.EXTRA_CHOSEN_COMPONENT)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 33
compileSdk 34

namespace 'io.flutter.plugins.shareexample'

Expand All @@ -40,8 +40,8 @@ android {

defaultConfig {
applicationId "io.flutter.plugins.shareexample"
minSdkVersion 19
targetSdkVersion 31
minSdk 19
targetSdk 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down

0 comments on commit b752fc3

Please sign in to comment.