我在团结的常规共享代码中遇到问题,它只在信使中工作,但在Instagram / twitter / facebook中失败,如下面的Facebook:没有任何东西出现,没有文字或图像。 Twitter:只显示文字,没有图片。 Whatsapp:分享失败/再试一次。 Instagram:不幸的是,Instagram已经停止了。 Snapchat:应用程序没有任何内容打开。
这是我的代码。
if (rayCast.collider != null && rayCast.transform.gameObject.tag == "share")
{
Debug.Log ("Capture SCreen");
Application.CaptureScreenshot ("Bla.png");
Debug.Log ("screen captured");
ShareImage (Application.persistentDataPath + "/sceenshot.png", "How many balloons you can tap in Yellow Hunter! ", "xx", "xx");
Debug.Log ("Sharing done");
}
public static void ShareImage(string imageFileName, string subject, string title, string message)
{
#if UNITY_ANDROID
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
intentObject.Call<AndroidJavaObject>("setType", "image/*");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), subject);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TITLE"), title);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), message);
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject fileObject = new AndroidJavaObject("java.io.File", imageFileName);
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("fromFile", fileObject);
bool fileExist = fileObject.Call<bool>("exists");
Debug.Log("File exist : " + fileExist);
// Attach image to intent
if (fileExist)
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("startActivity", intentObject);
#ENDIF