Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Share text or binary in Android — Gideros Forum

Share text or binary in Android

jdbcjdbc Member
edited October 2015 in Plugins
We can use Native plugin to send content to other apps in Android:

image

First, install bridge or native plugin.

Lua code within ui-android.lua:
--[[
    SHARE INTENT
]]--
 
Share = Core.class()
 
function Share:init()
 
	local share = native.getClass("com.giderosmobile.android.Share")
	share.sendText(activity)	
end
and create the following Share class in java:
package com.giderosmobile.android;
 
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
 
/**
 * Send content to other apps
 *
 */
public class Share {
 
    public static void sendText(Activity activity)
    {
		Intent sendIntent = new Intent();
		sendIntent.setAction(Intent.ACTION_SEND);
		sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
		sendIntent.setType("text/plain");
		activity.startActivity(sendIntent);
    }
}
Just use the following lua code to send text content
local share = ui.Share.new()
+1 -1 (+5 / -0 )Share on Facebook
«1

Comments

  • hgy29hgy29 Maintainer
    Stuff like that should become a native Gideros API IMHO

    Likes: keszegh, pie

    +1 -1 (+2 / -0 )Share on Facebook
  • can you also tell us how to do the other part, that is, make our app allow to receive a share of a file with a specific extension? thanks
  • Can someone who's used this confirmed it works still? I seem to remember GBridge/Native not working anymore, but can't find the forum thread.
    My Gideros games: www.totebo.com
  • GBridge works fine for me in android. Haven't yet tested iOS.

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • i have yet to test if this still works.
    hgy29 said:

    Stuff like that should become a native Gideros API IMHO

    - what's the opinion on this nowadays?
  • MoKaLuxMoKaLux Member
    edited July 2020
    are you kidding me?
    native plugin is working great, I need to play with this :o
    see the sample in gideros all plugins folder.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • The native plugin works great for Android. I wish we have a similar way to call Swift/ Objective-C like that.
    That way we can call almost native Android/iOS libraries like data analytics, ads network, utility ...
    Coming soon
  • hgy29hgy29 Maintainer
    isn't there a native plugin for iOS too ? I never used it but I remember seeing code for it in gideros sources
  • There was a BHwax Bridge for Ios by @bowerandy
    And there was a jvbridge for Android by @Javi
    Then @ar2rsawseen make a native plugin for android
    We can use "BHwax" and "jvbridge" as the keyword to search the forum for more information.
    Coming soon
  • jdbc said:

    We can use Native plugin to send content to other apps in Android:
    First, install bridge or native plugin.
    Lua code within ui-android.lua:
    and create the following Share class in java:

    Do you know guys in which folder we should put the java class?
    in: C:\Program Files (x86)\Gideros\All Plugins\native\bin\Android\src\com\giderosmobile\android\plugins\bridge

    or: C:\Program Files (x86)\Gideros\All Plugins\native\source\Android\src\com\giderosmobile\android\plugins\bridge
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • rrraptorrrraptor Member
    edited July 2020
    MoKaLux said:

    Do you know guys in which folder we should put the java class?
    in: C:\Program Files (x86)\Gideros\All Plugins\native\bin\Android\src\com\giderosmobile\android\plugins\bridge

    or: C:\Program Files (x86)\Gideros\All Plugins\native\source\Android\src\com\giderosmobile\android\plugins\bridge

    Perhaps, none of them? Depends on what you trying to do :)
  • @rrraptor you got me :) I was trying the example in the first post that is adding the share class. I thought there was 2 ways:
    - from inside gideros
    - from android studio

    I exported the native project from gideros to android studio but it is not nice to see :) Android studio just won't compile the project because of class name conflicts, ...

    So second solution would be to try from inside gideros, but where do we put the share java class? :)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • rrraptorrrraptor Member
    edited July 2020
    MoKaLux said:

    @rrraptor you got me :) I was trying the example in the first post that is adding the share class. I thought there was 2 ways:
    - from inside gideros
    - from android studio

    I exported the native project from gideros to android studio but it is not nice to see :) Android studio just won't compile the project because of class name conflicts, ...

    So second solution would be to try from inside gideros, but where do we put the share java class? :)

    It took me a while to figure out how to export with android studio but I did it.
    local OS = application:getDeviceInfo()
    local ERROR_LOADING_MODULE = ""
    local OK_LOADING_MODULE = ""
     
    if OS == "Android" then 
    	local ok, msg = pcall(require, "native")
    	if not ok then 
    		ERROR_LOADING_MODULE = msg
    	else
    		OK_LOADING_MODULE = "Detected 'native'\n"
    		-- print whats inside
    		for k,v in pairs(native) do 
    			OK_LOADING_MODULE = OK_LOADING_MODULE .. tostring(k) .. " - " .. tostring(value) .. "\n"
    		end
    	end
    else
    	ERROR_LOADING_MODULE = "Wrong OS =("
    end
    And when I press the "Share" button I call this function:
    function shareText(str)
    	local bridge = native.getClass("com.giderosmobile.android.plugins.bridge.GBridge")
    	local activity = bridge.getActivity()
    	local share = native.getClass("com.giderosmobile.android.Share")
    	share.sendText(activity, str)
    end
    But Im calling it in pcall:
    local ok, msg = pcall(shareText, "Hello there\nGeneral Kenobi")
    And app gets crushed after Im pressing the button.



    P.S. I also tried to call only native.getClass("com.giderosmobile.android.plugins.bridge.GBridge"), but result is the same.
    Screenshot_2020-07-02-11-15-28-598_com.yourdomain.yourapp.jpg
    1079 x 2263 - 94K
    image.png
    871 x 475 - 50K

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • edited July 2020
    Yes the error is
    JNI DETECTED ERROR IN APPLICATION: illegal class name 'com.giderosmobile.android.plugins.bridge.GBridge'
    java_vm_ext.cc:577] (should be of the form 'package/Class', [Lpackage/Class;' or '[[B')
    java_vm_ext.cc:577] in call to FindClass

    Last time when I test, I can resolve it by signing it with a keystone (not debug key)
    http://forum.giderosmobile.com/discussion/comment/57466/#Comment_57466
    http://forum.giderosmobile.com/discussion/5392/android-l-lollipop-doesnt-like-gideros

    But today when trying to build a test with a real Keystore on android 11, I still have the above error.
    We must try to fix it now...
    Coming soon
  • (at)rrraptor thank you for trying, my gideros plugins folder is all messed up right now, I need to reinstall gideros :)
    I will give it another try in the future when need arises.
    PEACE.
    What kind of plugin do you think can be done with the native plugin?
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • We must try to fix it now...

    It turns out that the fix is simple. Replace "." to "/".

    Now this code works:
    local bridge = native.getClass("com/giderosmobile/android/plugins/bridge/GBridge")
    local share = native.getClass("com/giderosmobile/android/Share")
    But this one:
    local activity = bridge.getActivity()
    Does not :(

    The error is now:
    JNI DETECTED ERROR IN APPLICATION: illegal class name 'com.giderosmobile.android.NativeTestActivity''

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • rrraptor said:

    The error is now:

    JNI DETECTED ERROR IN APPLICATION: illegal class name 'com.giderosmobile.android.NativeTestActivity''
    Yes that's where it gets nasty in android studio :)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • But today when trying to build a test with a real Keystore on android 11, I still have the above error.
    We must try to fix it now...

    Hold on. It works for me. No errors :D

    +1 -1 (+1 / -0 )Share on Facebook
  • @rrraptor With Android 11, the error will still there
    So at least, with android 10, we can use and test the native plugin.
    Android 11 will be coming soon in this July and I think we should fix this problem

    (I install your app, it open well, when press Share button, it errrors)

    2020-07-02 11:13:59.652 11459-11483/? A/rdomain.yourap: runtime.cc:662] JNI DETECTED ERROR IN APPLICATION: illegal class name 'com.giderosmobile.android.plugins.bridge.GBridge'
    runtime.cc:662] (should be of the form 'package/Class', [Lpackage/Class;' or '[[B')
    runtime.cc:662] in call to FindClass
    runtime.cc:662] from void com.giderosmobile.android.player.GiderosApplication.nativeDrawFrame()

    --------- beginning of crash
    2020-07-02 11:13:59.652 11459-11483/? A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 11483 (GLThread 6746), pid 11459 (rdomain.yourapp)
    2020-07-02 11:13:59.683 11508-11508/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    2020-07-02 11:13:59.684 11508-11508/? A/DEBUG: Build fingerprint: 'google/flame/flame:11/RPB1.200504.020/6557529:user/release-keys'
    2020-07-02 11:13:59.684 11508-11508/? A/DEBUG: Revision: 'MP1.0'
    2020-07-02 11:13:59.684 11508-11508/? A/DEBUG: ABI: 'arm64'
    2020-07-02 11:13:59.684 11508-11508/? A/DEBUG: Timestamp: 2020-07-02 11:13:59+0700
    2020-07-02 11:13:59.684 11508-11508/? A/DEBUG: pid: 11459, tid: 11483, name: GLThread 6746 >>> com.yourdomain.yourapp <<<
    2020-07-02 11:13:59.684 11508-11508/? A/DEBUG: uid: 10277
    2020-07-02 11:13:59.684 11508-11508/? A/DEBUG: signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
    2020-07-02 11:13:59.684 11508-11508/? A/DEBUG: Abort message: 'JNI DETECTED ERROR IN APPLICATION: illegal class name 'com.giderosmobile.android.plugins.bridge.GBridge'
    (should be of the form 'package/Class', [Lpackage/Class;' or '[[B')
    in call to FindClass
    from void com.giderosmobile.android.player.GiderosApplication.nativeDrawFrame()'
    Coming soon
  • I hate google for changing code every new release >:)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • hgy29hgy29 Maintainer
    Can anyone try native plugin on Android 11 with these patched libs (All Plugins/native/bin/Android) ?
    zip
    zip
    libs.zip
    484K
    libs.zip 483.7K
    +1 -1 (+3 / -0 )Share on Facebook
  • edited July 2020
    @hgy29 It works! What can I say now? You are a superhero!
    Using your patch, we can still use dot symbol (.), not the slash (/)

    if not native then
    require "native"
    end
    local bridge = native.getClass("com.giderosmobile.android.plugins.bridge.GBridge")
    local activity = bridge.getActivity()
    local toast = native.getClass("android.widget.Toast")
    local t = toast.makeText(activity, "Hello Gideros", 2)
    t:show()

    Likes: MoKaLux

    Coming soon
    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    ok, I'll commit the changes to GH then, they'll be in next release
    +1 -1 (+2 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    While we are at it, I had a an unfinished share plugin in my Gideros source tree. It is still unfinished, but can be used to share texts. It supports iOS and Android. Anyone wanting to try it ?

    Usage:
    (require "Share").share("text/plain","Share this text!")
    zip
    zip
    share.zip
    365K
  • SinisterSoftSinisterSoft Maintainer
    Do you mean to the paste buffer? Or does a dialog appear?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • rrraptorrrraptor Member
    edited July 2020
    @hgy29 I cant compile because there is a few errors.
    First,
    import android.content.Intent;
    Second,
    if (mimeType.startsWith("text/"))
    	-- replace sendIntent to shareIntent
    	shareIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
    Third,
    getResources().getText(R.string.send_to)
    Cannot resolve method 'getResources' in 'Share'
    But It can be replaced with any string.

    And finally:
    error: cannot find symbol
    		startActivity(Intent.createChooser(shareIntent, "Title"));
    		^
      symbol:   method startActivity(Intent)
      location: class Share
Sign In or Register to comment.