1
我最近在Play商店發佈了一款遊戲。在遊戲中有一個分享按鈕,使用來自資產的促銷圖片,使用Android本地分享實用程序添加一些文字和分享。我知道FB不允許用戶輸入文字,但圖像總是無法添加到文章中。Unity Android - 圖片分享到Facebook失敗
我已經在這個問題上打了很多天了。我安裝了Facebook SDK,這本身並沒有解決問題,但我不知道如何繼續按下按鈕來允許用戶選擇共享時使用哪種服務,而不是僅使用Facebook sdk共享。
下面是我使用的代碼:
yield return new WaitForEndOfFrame();
if (!Application.isEditor)
{
string fromPath = "jar:file://" + Application.dataPath + "!/assets/";
string toPath = Application.persistentDataPath + "/";
string[] filesNamesToCopy = new string[] { "a.txt", "b.txt" };
foreach (string fileName in filesNamesToCopy)
{
Debug.Log("copying from " + fromPath + fileName + " to " + toPath);
WWW www1 = new WWW(fromPath + fileName);
yield return www1;
Debug.Log("yield done");
File.WriteAllBytes(toPath + fileName, www1.bytes);
Debug.Log("file copy done");
}
// code to open the image and share it
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", "jar:file://" + Application.dataPath + "!/assets/" + "Promo.jpg");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
intentObject.Call<AndroidJavaObject>("setType", "text/plain");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), "I scored " + score + " in Space Drill, try to beat me! #spacedrill https://play.google.com/store/apps/details?id=com.AbsinthePie.space_drill");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), "SUBJECT");
intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("startActivity", intentObject);
}
任何提示或建議將不勝感激。 感謝您的閱讀!
您不使用Facebook SDK團結有什麼特別的理由這樣做?他們有一個功能,可以讓你在分享時從本地存儲中添加圖片 –