Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1) Added support Gradle 6.5 #136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'com.kasem.receive_sharing_intent'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.31'
ext.kotlin_version = '1.4.21'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -25,7 +25,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import android.graphics.Bitmap
import android.media.MediaMetadataRetriever
import android.media.ThumbnailUtils
import android.net.Uri
import android.os.CancellationSignal
import android.provider.MediaStore
import android.util.Size
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
Expand All @@ -16,8 +18,8 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar
import io.flutter.plugin.common.PluginRegistry.NewIntentListener
import io.flutter.plugin.common.PluginRegistry.Registrar
import org.json.JSONArray
import org.json.JSONObject
import java.io.File
Expand Down Expand Up @@ -128,12 +130,12 @@ class ReceiveSharingIntentPlugin : FlutterPlugin, ActivityAware, MethodCallHandl
latestText = value
eventSinkText?.success(latestText)
}
intent.action == Intent.ACTION_VIEW -> { // Opening URL
val value = intent.dataString
if (initial) initialText = value
latestText = value
eventSinkText?.success(latestText)
}
// intent.action == Intent.ACTION_VIEW -> { // Opening URL
// val value = intent.dataString
// if (initial) initialText = value
// latestText = value
// eventSinkText?.success(latestText)
// }
}
}

Expand All @@ -142,7 +144,7 @@ class ReceiveSharingIntentPlugin : FlutterPlugin, ActivityAware, MethodCallHandl

return when (intent.action) {
Intent.ACTION_SEND -> {
val uri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
val uri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM) ?: return null
val path = FileDirectory.getAbsolutePath(applicationContext, uri)
if (path != null) {
val type = getMediaType(path)
Expand Down Expand Up @@ -191,8 +193,16 @@ class ReceiveSharingIntentPlugin : FlutterPlugin, ActivityAware, MethodCallHandl

val videoFile = File(path)
val targetFile = File(applicationContext.cacheDir, "${videoFile.name}.png")
val bitmap = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.MINI_KIND)
?: return null

@Suppress("DEPRECATION")
val bitmap = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
val mSize = Size(96, 96)
val ca = CancellationSignal()
ThumbnailUtils.createVideoThumbnail(videoFile, mSize, ca)
} else {
ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.MINI_KIND)
?: return null
}
FileOutputStream(targetFile).use { out ->
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
}
Expand All @@ -204,7 +214,7 @@ class ReceiveSharingIntentPlugin : FlutterPlugin, ActivityAware, MethodCallHandl
if (type != MediaType.VIDEO) return null // get duration for video only
val retriever = MediaMetadataRetriever()
retriever.setDataSource(path)
val duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION).toLongOrNull()
val duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)?.toLongOrNull()
retriever.release()
return duration
}
Expand Down
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.kasem.receive_sharing_intent_example"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.31'
ext.kotlin_version = '1.4.21'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
3 changes: 0 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@
/* Begin XCBuildConfiguration section */
249021D3217E4FDB00AE95B9 /* Profile */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -604,7 +603,6 @@
};
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -659,7 +657,6 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down
17 changes: 1 addition & 16 deletions ios/Classes/SwiftReceiveSharingIntentPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SwiftReceiveSharingIntentPlugin: NSObject, FlutterPlugin, FlutterSt
static let kEventsChannelMedia = "receive_sharing_intent/events-media";
static let kEventsChannelLink = "receive_sharing_intent/events-text";

private var customSchemePrefix = "ShareMedia";
private var customSchemePrefix = "ShareToLocalsCom";

private var initialMedia: [SharedMediaFile]? = nil
private var latestMedia: [SharedMediaFile]? = nil
Expand Down Expand Up @@ -99,21 +99,6 @@ public class SwiftReceiveSharingIntentPlugin: NSObject, FlutterPlugin, FlutterSt
return true
}

// This function is called by other modules like Firebase DeepLinks.
// It tells the delegate that data for continuing an activity is available. Returning true means that our module handled the activity and that others do not have to. Returning false tells
// iOS that our app did not handle the activity.
// If the URL includes the module's ShareMedia prefix, then we process the URL and return true if we know how to handle that kind of URL or false if we are not able to.
// If the URL does not include the module's prefix, then we must return false to indicate that this module did not handle the prefix and that other modules should try to.
// Reference: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623072-application
public func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]) -> Void) -> Bool {
if let url = userActivity.webpageURL {
if (hasMatchingSchemePrefix(url: url)) {
return handleUrl(url: url, setInitialData: true)
}
}
return false
}

private func handleUrl(url: URL?, setInitialData: Bool) -> Bool {
if let url = url {
let appDomain = Bundle.main.bundleIdentifier!
Expand Down