godot icon indicating copy to clipboard operation
godot copied to clipboard

Add support for iOS mobile share API

Open theromis opened this issue 1 year ago • 2 comments
trafficstars

Recreating https://github.com/godotengine/godot/pull/90429 ability to share text and added rate in app option

theromis avatar Apr 29 '24 13:04 theromis

Also I can add android version for share and rate, but seems like I have to add few functions into platform/android/display_server_android.cpp for it

theromis avatar Oct 04 '24 05:10 theromis

class GodotShare(godot: Godot) : GodotPlugin(godot) {
    private val logTag = "godot::GodotShare"
    private val mimeTypeText = "text/plain"
    private val mimeTypeImage = "image/*"
    private val fileProvider = ".sharefileprovider"

    override fun getPluginName() = "GodotShare"

    @UsedByGodot
    fun share(text: String, subject: String, title: String, path: String) {
        //Log.d(logTag, "share() called with path $path")
        val shareIntent = Intent(Intent.ACTION_SEND)
        shareIntent.setType(mimeTypeImage)
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
        if (text.isNotEmpty()) {
            shareIntent.putExtra(Intent.EXTRA_TEXT, text)
        }
        if (subject.isNotEmpty()) {
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject)
        }
        if (path.isNotEmpty()) {
            val f = File(path)
            val uri: Uri = try {
                FileProvider.getUriForFile(activity!!, activity!!.packageName+fileProvider, f)
            } catch (e: IllegalArgumentException) {
                Log.e(logTag, "The selected file can't be shared: $path", e)
                return
            }
            shareIntent.clipData = ClipData.newRawUri("", uri)
            shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
        }
        activity?.startActivity(Intent.createChooser(shareIntent, title))
    }
}

Is it right approach to implement this Kotlin code as godot_java wrapper?

theromis avatar Oct 04 '24 06:10 theromis

The last action on this PR was 7 months ago. Would be great to get this into the 4.5 Release. Why is there no action on this anymore? I cant see any comments with a reason why this cant be merged.

ElQDuck avatar May 14 '25 14:05 ElQDuck

I cant see any comments with a reason why this cant be merged.

To me this feels like something that should be an iOS plugin. Or, at the very least, it should add a clearly iOS-only API, rather than a singleton with a very generic name (GodotShare) that only works on iOS.

On the Android side, I don't think we have anything like this built into Godot, it would be something done in an Android plugin, or now with JavaClassWrapper.

dsnopek avatar May 14 '25 14:05 dsnopek

I have java Android plugin, we can discuss how it can be integrated into JavaClassWrapper

theromis avatar May 14 '25 16:05 theromis