Unity分享Facebook,Twitter,whatsapp E.t.c Android [英] Unity Sharing Facebook,Twitter,whatsapp E.t.c Android

查看:219
本文介绍了Unity分享Facebook,Twitter,whatsapp E.t.c Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想在Twitter和Facebook上分享我的游戏,这个脚本可以让我分享一下twitter的内容,whatsapp,但是我无法在Facebook上分享它,它不会在Facebook上显示文本,而是在Twitter上显示文本,而且我不会知道如何添加到脚本,所以它需要游戏的截图,并添加到帖子请帮助我出来



对不起,英文不好,

这是ShareScript。



感谢您的帮助:)

 使用UnityEngine; 
使用System.Collections;
使用UnityEngine.UI;
使用System.IO;

public class ShareMenu:MonoBehaviour
{

private bool isProcessing = false;

私人字符串shareText =下载此游戏;
私人字符串gameLink =在游戏商店下载游戏+\\\
https://play.google.com/store/apps/details?id = com.CrazyDrivers;
private string imageName =MyPic; //没有扩展名,对于iinstance,MyPic
public void shareImage()
{

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

}

私有IEnumerator ShareScreenshot()
{
isProcessing = true;
yield返回新的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;

}

}


解决方案

没有尝试您的脚本,但问题可能在Facebook共享策略。 以下是一些信息



长篇小说 - Facebook不允许预先填写的文字。
看到这个问题


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;

    }

}

解决方案

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

这篇关于Unity分享Facebook,Twitter,whatsapp E.t.c Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆