Unity分享Facebook,Twitter,whatsapp E.t.c Android

时间:2016-07-11 07:57:04

标签: android facebook unity3d unity5

您好我想在Twitter和Facebook上分享我的游戏,这个脚本允许我分享详细信息到twitter,whatsapp但我不能在Facebook上分享它不会在Facebook上显示文字,但在Twitter和whatsapp它确实,我不知道如何添加To脚本所以它需要截取游戏并将其添加到帖子中请帮助我

抱歉英文不好

这是ShareScript。

感谢您的帮助:)

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;

public class ShareMenu : MonoBehaviour
{

    private bool isProcessing = false;

    private string shareText = "Download This Game";
    private string gameLink = "Download the game on play store at " + "\nhttps://play.google.com/store/apps/details?id=com.CrazyDrivers";
    private string imageName = "MyPic"; // without the extension, for iinstance, MyPic 
    public void shareImage()
    {

        if (!isProcessing)
            StartCoroutine(ShareScreenshot());

    }

    private IEnumerator ShareScreenshot()
    {
        isProcessing = true;
        yield return new WaitForEndOfFrame();

        Texture2D screenTexture = new Texture2D(1080, 1080, TextureFormat.RGB24, true);
        screenTexture.Apply();


        string destination = Path.Combine(Application.persistentDataPath, System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".png");
        Debug.Log(destination);

        if (!Application.isEditor)
        {

            AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
            AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
            intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
            AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
            AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + destination);
            intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
            intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), shareText + gameLink);
            intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");
            AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");

            currentActivity.Call("startActivity", intentObject);

        }

        isProcessing = false;

    }

}

1 个答案:

答案 0 :(得分:0)

没有尝试过您的脚本,但问题可能出在Facebook共享策略中。 Here is some information

长话短说 - facebook不允许预填充文字。 See this question