Unity Sharing Facebook,Twitter,whatsapp E.t.c Android

▼魔方 西西 提交于 2019-12-23 05:23:02

问题


Hello i want to share my game on twitter and Facebook , this script allows me to share details to twitter , whatsapp but i cant share on facebook it doesnt show text on facebook , but on twitter and whatsapp it does , And i dont know how to add in To script so it takes screenshot of game and Adds it to post Please help me out

Sorry for bad English

And Here is ShareScript.

Thanks for help :)

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:


Didn't try your script, but the problem may be in facebook sharing policy. Here is some information.

Long story short — facebook does not allow prefilled text. See this question



来源:https://stackoverflow.com/questions/38301836/unity-sharing-facebook-twitter-whatsapp-e-t-c-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!