Unity分享Facebook,Twitter,whatsapp E.t.c Android [英] Unity Sharing Facebook,Twitter,whatsapp E.t.c Android
问题描述
对不起,英文不好,
这是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屋!