Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Bug fixes and updated api names
Browse files Browse the repository at this point in the history
  • Loading branch information
KasemJaffer committed Jun 20, 2019
1 parent 7b59ae6 commit 398d326
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 137 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# receive_sharing_intent

A flutter plugin that enables flutter apps to receive sharing photos from other apps.
A flutter plugin that enables flutter apps to receive sharing photos, text and urls from other apps.

Also, supports iOS Share extension and launching the host app automatically.
Check the provided example for more info.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class ReceiveSharingIntentPlugin(val registrar: Registrar) :
PluginRegistry.NewIntentListener {

private var changeReceiverImage: BroadcastReceiver? = null
private var changeReceiverLink: BroadcastReceiver? = null
private var changeReceiverText: BroadcastReceiver? = null

private var initialIntentData: ArrayList<String>? = null
private var latestIntentData: ArrayList<String>? = null

private var initialLink: String? = null
private var latestLink: String? = null
private var initialText: String? = null
private var latestText: String? = null

init {
handleIntent(registrar.context(), registrar.activity().intent, true)
Expand All @@ -34,14 +34,14 @@ class ReceiveSharingIntentPlugin(val registrar: Registrar) :
override fun onListen(arguments: Any?, events: EventChannel.EventSink) {
when (arguments) {
"image" -> changeReceiverImage = createChangeReceiver(events)
"link" -> changeReceiverLink = createChangeReceiver(events)
"text" -> changeReceiverText = createChangeReceiver(events)
}
}

override fun onCancel(arguments: Any?) {
when (arguments) {
"image" -> changeReceiverImage = null
"link" -> changeReceiverLink = null
"text" -> changeReceiverText = null
}
}

Expand All @@ -53,7 +53,7 @@ class ReceiveSharingIntentPlugin(val registrar: Registrar) :
companion object {
private val MESSAGES_CHANNEL = "receive_sharing_intent/messages"
private val EVENTS_CHANNEL_IMAGE = "receive_sharing_intent/events-image"
private val EVENTS_CHANNEL_LINK = "receive_sharing_intent/events-link"
private val EVENTS_CHANNEL_TEXT = "receive_sharing_intent/events-text"

@JvmStatic
fun registerWith(registrar: Registrar) {
Expand All @@ -70,8 +70,8 @@ class ReceiveSharingIntentPlugin(val registrar: Registrar) :
val eChannelImage = EventChannel(registrar.messenger(), EVENTS_CHANNEL_IMAGE)
eChannelImage.setStreamHandler(instance)

val eChannelLink = EventChannel(registrar.messenger(), EVENTS_CHANNEL_LINK)
eChannelLink.setStreamHandler(instance)
val eChannelText = EventChannel(registrar.messenger(), EVENTS_CHANNEL_TEXT)
eChannelText.setStreamHandler(instance)

registrar.addNewIntentListener(instance)
}
Expand All @@ -81,7 +81,7 @@ class ReceiveSharingIntentPlugin(val registrar: Registrar) :
override fun onMethodCall(call: MethodCall, result: Result) {
when {
call.method == "getInitialIntentData" -> result.success(initialIntentData)
call.method == "getInitialLink" -> result.success(initialLink)
call.method == "getInitialText" -> result.success(initialText)
else -> result.notImplemented()
}
}
Expand All @@ -90,20 +90,25 @@ class ReceiveSharingIntentPlugin(val registrar: Registrar) :
when {
intent.type?.startsWith("image") == true
&& (intent.action == Intent.ACTION_SEND
|| intent.action == Intent.ACTION_SEND_MULTIPLE) -> {
|| intent.action == Intent.ACTION_SEND_MULTIPLE) -> { // Sharing images

val value = getImageUris(intent)
if (initial) initialIntentData = value
latestIntentData = value
changeReceiverImage?.onReceive(context, intent)
}
(intent.type == null || intent.type?.startsWith("text") == true)
&& (intent.action == Intent.ACTION_SEND
|| intent.action == Intent.ACTION_VIEW) -> {
&& intent.action == Intent.ACTION_SEND -> { // Sharing text
val value = intent.getStringExtra(Intent.EXTRA_TEXT)
if (initial) initialText = value
latestText = value
changeReceiverText?.onReceive(context, intent)
}
intent.action == Intent.ACTION_VIEW -> { // Opening URL
val value = intent.dataString
if (initial) initialLink = value
latestLink = value
changeReceiverLink?.onReceive(context, intent)
if (initial) initialText = value
latestText = value
changeReceiverText?.onReceive(context, intent)
}
}
}
Expand Down Expand Up @@ -134,8 +139,8 @@ class ReceiveSharingIntentPlugin(val registrar: Registrar) :
&& (intent.action == Intent.ACTION_SEND
|| intent.action == Intent.ACTION_SEND_MULTIPLE) -> getImageUris(intent)
(intent?.type == null || intent.type?.startsWith("text") == true)
&& (intent?.action == Intent.ACTION_SEND
|| intent?.action == Intent.ACTION_VIEW) -> intent.dataString
&& intent?.action == Intent.ACTION_SEND -> intent.getStringExtra(Intent.EXTRA_TEXT)
intent?.action == Intent.ACTION_VIEW -> intent.dataString
else -> null
}

Expand Down
Loading

0 comments on commit 398d326

Please sign in to comment.