Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Android native share — Gideros Forum

Android native share

totebototebo Member
edited September 2014 in Plugins
Is there a wrapper to the "send binary content" (as per link below), or any other way of triggering this?

http://developer.android.com/training/sharing/send.html#send-binary-content

Niclas
My Gideros games: www.totebo.com

Comments

  • Hey peeps, no info on this seemingly common feature on Android?!
    My Gideros games: www.totebo.com
  • I don't think it is possible without a plugin. But writing plugins in Gideros is easy though no need to afraid. There are so much good tutorials and examples on this subject in the forum. Just search and you will find.
  • @totebo it is easy if you are using Gbridge
    http://giderosmobile.com/labs/native-ui
    simply create a method in GBridge.java class with basically same contents as in your link
    And call it in lua

    here is more discussion on it:
    http://giderosmobile.com/forum/discussion/comment/34701#Comment_34701
  • Thanks a lot, will try this! :)
    My Gideros games: www.totebo.com
  • larflarf Member
    @totebo Did you ever get this to work for you?
    I'd love to use native share in android if it's not too much work.
  • tkhnomantkhnoman Member
    edited April 2015
    public static void shareThat(int id, String text){
    	Intent sendIntent = new Intent();
    	sendIntent.setAction(Intent.ACTION_SEND);
    	sendIntent.putExtra(Intent.EXTRA_TEXT, text);
    	sendIntent.setType("text/plain");
    	sActivity.get().startActivity(Intent.createChooser(sendIntent, sActivity.get().getResources().getText(R.string.send_to)));
    	}
    The code is something like this.

    and then on values/String.xml add:
     <string name="send_to">Share this text to</string>
    I can't share the plugin because i modified another plugin for this.
    It won't me no much work if you just modify another plugin, for example Ads Interface plugin. In this case, i modified loadAd.
    (sActivity is private WeakReference which i got from Ads Interface plugin)
  • larflarf Member
    Thanks for the advice @tkhnoman.
    I'm pretty much a noob at native android programming.

    I think I might try adding a function to Gbridge like @ar2rsawseen suggested,
    it seems like that might be easier.

    If I can't get it to work i'll try making my own plugin.

    What I really want to do is take a screen shot with media plugin and share it with some text. Seems like it should be possible with Gbridge.
  • Hey @larf, I took a screenshot and shared it with the native Android share in No Brakes. It worked pretty well, although for unknown reason images were saved as heavily compressed jpegs, even though I specified PNG in the GBridge method in Java. After Lollipop was released, however, I got a flood of crash reports coming in from Crashlytics, so I went for the safe option and removed the screenshot capability on Android. I'm guessing this was down to my Java coding skills (inexistent).

    If you do get it to work, please share! :)

    Niclas
    My Gideros games: www.totebo.com
  • larflarf Member
    edited April 2015
    Hi @totebo. thanks for the reply! Looks like we're in a similar boat (non existant java skills). I've managed to create a function in Gbridge and activate the android share intent. I haven't tried to send images captured by media plugin yet, but my test images showed up without any trouble. I'm testing on a nexus 7 running android L.

    For anyone interested here's my Gbridge function

    public static void ShareImage(String image_path)
    {
    Uri uriToImage = Uri.parse(image_path);
    Intent shareIntent = new Intent();
    shareIntent.putExtra(Intent.EXTRA_TEXT, "example text");
    shareIntent.putExtra(Intent.EXTRA_TITLE, "example title");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "example subject");
    shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
    shareIntent.setType("image/*");
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    sActivity.get().startActivity(Intent.createChooser(shareIntent, "Share score using"));
    }

    needed to import these at the top of Gbridge

    import android.content.Context;
    import android.content.Intent;

    Here's what I call in my project

    local image_path = native.getPath("|R|images/share.png")
    local bridge = native.getClass("com.giderosmobile.android.plugins.bridge.GBridge")--bridge.ShareImage("file://" .. image_path)

    This works for twitter, gmail, etc, just a few problems.

    problem 1:
    Every time I try to share anything to Facebook via the android intent it I get
    "Please attach only photos or a single video."

    After some searching it seems like facebook doesn't accept posts from android share intent with with pre-filled text.
    I can't even get it to work if I try to just share an image.
    Did you have any luck with this?

    I spent a day trying to integrate this into my project with limited success
    https://github.com/b099l3/FacebookImageShareIntent
    However, every time it to post successfully my app crashes

    problem 2:
    I'm having a similar issue to what you're experiencing here:
    http://giderosmobile.com/forum/discussion/5392/android-l-lollipop-doesnt-like-gideros/p1
    JNI DETECTED ERROR IN APPLICATION: illegal class name 'com.giderosmobile.android.plugins.bridge.GBridge'

    Only i'm not doing anything with sound, just calling
    native.getClass("com.giderosmobile.android.plugins.bridge.GBridge")
    seems to cause it.
    Interestingly, it only happens when I'm in debugging mode in ecliplse.
    If i sign and export the project it doesn't happen.

    If I get things working a bit better i'll post an update
  • larflarf Member
    So, after another day of googleing and trying different things, I managed to get the Facebook share intent from https://github.com/b099l3/FacebookImageShareIntent to work and not crash!

    If anyone is interested in trying to use it I can maybe help them get it to work.
  • Well done @larf, you hung in there! :) I may want to pick your brain at some point when I need this functionality again.
    My Gideros games: www.totebo.com
Sign In or Register to comment.