[IOS/Android] Simple Share to email/Twitter/Facebook etc[V1.9.6]

rob1221

  • *
  • Posts: 9424
I think that would be going too far away from the scope of this extension, and it would make more sense to have a separate Facebook extension that includes more than just a simple share.

robinschaafsma

  • *
  • Posts: 712
Rob is right, it is not the scope of this extension. It is a simple share extension, without the SDK's, and it is more sense to have a separate Facebook extension.

Bhoopalan

  • Posts: 1015
No harm, Robin. You've really done a great work. I just wish it's complete though :)
If I helped you at anytime, help me back build my twitter followers :)
https://twitter.com/imbhoopalan

Max Finch

  • *
  • Posts: 2183
No harm, Robin. You've really done a great work. I just wish it's complete though :)

It is complete.

Bhoopalan

  • Posts: 1015
No harm, Robin. You've really done a great work. I just wish it's complete though :)

It is complete.

Probably I used the wrong word. I'm sorry again if that was hurting or disappointing. I just wish the sharing works with fb in android including the message.
If I helped you at anytime, help me back build my twitter followers :)
https://twitter.com/imbhoopalan

Raiyumi

  • *
  • Posts: 204
This is nice, although it seems to be crashing on my Samsung Galaxy Tab 3 when I have "Take a screenshot" to Yes.

gcm

  • Posts: 29
Thanks for sharing the extention.

Is it normal to take a 5-8 second to open "share window" after pressing the corresponding button?

SolDiez

  • Posts: 33
On my Nexus 2012 tablet, android kit kat, when trying to take a screenshot the whole game crashes. On my other thl t6s phone, everything is working fine. Does anybody have a solution?

Thanks!

SolDiez

  • Posts: 33
I poked around the extension a bit and figured it out. There's a problem with devices that only have phone storage. It's not necesarily about having an sd card since some phones have the storage split in 2 even if they have no sd card, and the extension works on those phones also. I fixed it by only writing the screenshot to internal storage, so now it works on all phones.

My fix isn't ideal since it uses a deprecated mode for "openFileOutput", but it should do the trick until someone can fix it the proper way.

You have to replace the contents of the Share.java file, somewhere inside the extension's folder, with this

Code: [Select]
/**
 *
 * Stencyl Extension, Create by Robin Schaafsma
 * wwww.byrobingames.com
 *
 **/

package com.byrobin.simpleshare;

import org.haxe.lime.*;
import android.content.Intent;

import android.app.Activity;
import android.content.res.AssetManager;
import android.content.Context;
import android.content.ContentValues;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
import android.net.Uri;
import android.graphics.Bitmap;
import android.util.Base64;
import android.provider.MediaStore;
import android.util.Log;

import org.haxe.extension.Extension;

public class Share extends Extension
{
   
    public static String path;
    public static Uri uri;
   
    private static boolean shareSucceed = false;
    private static boolean shareFailed = false;

    public static void shareContent(final String msg, final String url, final boolean withImage)
{
       
        mainActivity.runOnUiThread(new Runnable()
        {
        public void run()
{
               
                if(!withImage)
                {

                    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    intent.putExtra(Intent.EXTRA_TEXT, msg + "\n\n" + url);
                    Extension.mainContext.startActivity(Intent.createChooser(intent, "Share via..."));
                   
                    shareSucceed = true;
                    shareFailed = false;
                   
                }
                   
            }
        });
    }
   
   
    public static void saveImageAndShare (final String msg, final String url, final String base64Img)
    {
        mainActivity.runOnUiThread(new Runnable()
                                   {
            public void run()
            {
        Bitmap image = convertToImage(base64Img);
                /*    String path = MediaStore.Images.Media.insertImage(Extension.mainContext.getContentResolver(), convertToImage(base64Img), "Screenshot" , "Drawing");*/

//Comment: path - Extension.mainContext.getCacheDir() &

try {
// Use the compress method on the Bitmap object to write image //to
// the OutputStream
FileOutputStream fos = Extension.mainContext.openFileOutput("screen.png", Context.MODE_WORLD_READABLE);

// Writing the bitmap to the output stream
image.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();

} catch (Exception e) {
Log.e("saveToInternalStorage()", e.getMessage());
}

File filePath = Extension.mainContext.getFileStreamPath("screen.png");

Log.e("file path ", filePath.toString());

Uri fileUri = Uri.fromFile(filePath);
       
                    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                    intent.setType("image/jpeg");
                    intent.putExtra(Intent.EXTRA_TEXT, msg + "\n\n" + url);
                    intent.putExtra(Intent.EXTRA_STREAM, fileUri);
                    Extension.mainContext.startActivity(Intent.createChooser(intent, "Share via.."));

                    shareSucceed = true;
                    shareFailed = false;
            }
        });
    }
   
    public static Bitmap convertToImage(String image)
    {
        try
        {
            InputStream stream = new ByteArrayInputStream(Base64.decode(image.getBytes(), Base64.DEFAULT));
            Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(stream);
            return bitmap;
        }
        catch (Exception e)
        {
            return null;
        }
    }
   
   
    static public boolean shareResultSucceed()
    {
        if(shareSucceed)
        {
            shareSucceed = false;
            return true;
        }
        return false;
    }
   
    static public boolean shareResultFailed()
    {
        return shareFailed;
    }

}

Hope it helps!

robinschaafsma

  • *
  • Posts: 712
I poked around the extension a bit and figured it out. There's a problem with devices that only have phone storage. It's not necesarily about having an sd card since some phones have the storage split in 2 even if they have no sd card, and the extension works on those phones also. I fixed it by only writing the screenshot to internal storage, so now it works on all phones.

My fix isn't ideal since it uses a deprecated mode for "openFileOutput", but it should do the trick until someone can fix it the proper way.

You have to replace the contents of the Share.java file, somewhere inside the extension's folder, with this

Code: [Select]
/**
 *
 * Stencyl Extension, Create by Robin Schaafsma
 * wwww.byrobingames.com
 *
 **/

package com.byrobin.simpleshare;

import org.haxe.lime.*;
import android.content.Intent;

import android.app.Activity;
import android.content.res.AssetManager;
import android.content.Context;
import android.content.ContentValues;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
import android.net.Uri;
import android.graphics.Bitmap;
import android.util.Base64;
import android.provider.MediaStore;
import android.util.Log;

import org.haxe.extension.Extension;

public class Share extends Extension
{
   
    public static String path;
    public static Uri uri;
   
    private static boolean shareSucceed = false;
    private static boolean shareFailed = false;

    public static void shareContent(final String msg, final String url, final boolean withImage)
{
       
        mainActivity.runOnUiThread(new Runnable()
        {
        public void run()
{
               
                if(!withImage)
                {

                    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    intent.putExtra(Intent.EXTRA_TEXT, msg + "\n\n" + url);
                    Extension.mainContext.startActivity(Intent.createChooser(intent, "Share via..."));
                   
                    shareSucceed = true;
                    shareFailed = false;
                   
                }
                   
            }
        });
    }
   
   
    public static void saveImageAndShare (final String msg, final String url, final String base64Img)
    {
        mainActivity.runOnUiThread(new Runnable()
                                   {
            public void run()
            {
        Bitmap image = convertToImage(base64Img);
                /*    String path = MediaStore.Images.Media.insertImage(Extension.mainContext.getContentResolver(), convertToImage(base64Img), "Screenshot" , "Drawing");*/

//Comment: path - Extension.mainContext.getCacheDir() &

try {
// Use the compress method on the Bitmap object to write image //to
// the OutputStream
FileOutputStream fos = Extension.mainContext.openFileOutput("screen.png", Context.MODE_WORLD_READABLE);

// Writing the bitmap to the output stream
image.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();

} catch (Exception e) {
Log.e("saveToInternalStorage()", e.getMessage());
}

File filePath = Extension.mainContext.getFileStreamPath("screen.png");

Log.e("file path ", filePath.toString());

Uri fileUri = Uri.fromFile(filePath);
       
                    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                    intent.setType("image/jpeg");
                    intent.putExtra(Intent.EXTRA_TEXT, msg + "\n\n" + url);
                    intent.putExtra(Intent.EXTRA_STREAM, fileUri);
                    Extension.mainContext.startActivity(Intent.createChooser(intent, "Share via.."));

                    shareSucceed = true;
                    shareFailed = false;
            }
        });
    }
   
    public static Bitmap convertToImage(String image)
    {
        try
        {
            InputStream stream = new ByteArrayInputStream(Base64.decode(image.getBytes(), Base64.DEFAULT));
            Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(stream);
            return bitmap;
        }
        catch (Exception e)
        {
            return null;
        }
    }
   
   
    static public boolean shareResultSucceed()
    {
        if(shareSucceed)
        {
            shareSucceed = false;
            return true;
        }
        return false;
    }
   
    static public boolean shareResultFailed()
    {
        return shareFailed;
    }

}

Hope it helps!

Thanks, i will update this soon.

robinschaafsma

  • *
  • Posts: 712
**EDIT UPDATE version 1.6( 2015-05-16)**
- Android: Save screenshot to phone storage(thanks SolDiez)

sebstarr

  • *
  • Posts: 259
I uploaded my game to Android and iOS, yesterday.

I've had lots of people telling me that they've had problems with sharing. I've just tried and it's the same with me.

It seems to only take a screenshot of the top left hand corner. So it's not showing the score, high score etc.

letmethink

  • *
  • Posts: 2547
That's a Stencyl problem of getting screen as image. It is not to do with this extension specifically as far as I know.
~Letmethink

Max Finch

  • *
  • Posts: 2183
I uploaded my game to Android and iOS, yesterday.

I've had lots of people telling me that they've had problems with sharing. I've just tried and it's the same with me.

It seems to only take a screenshot of the top left hand corner. So it's not showing the score, high score etc.

I attempted to fix Stencyl's screenshot logic a while back. Unfortunately I only made it a tad better. I'll see if I can't try something else again for the heck of it.

Northfield82

  • Posts: 649
I've just installed the simple sharing extension and have the following issue (Android):

When I go to share on Facebook using the Facebook App, it does not carry the message over, however it still carries the screenshot over.

If I go to share via email, it works fine with both message and screenshot.

Anyone else having trouble with this?