2013年11月11日 星期一

Share your image to other APP such like Facebook,LINE or Gmail in Unity3D with Plungin.(Android)


If you do a app that have camera function with Unity3D, you may want to share the picture

to other social Apps ,facebook or Line .Here were  the roughly codes.Try it.

ADT:

private void ShareImage(string filePath) {
Intent share = new Intent(Intent.ACTION_SEND);

// Make sure you put image in the Directory
String imagePath =  filePath

File imageFileToShare = new File(imagePath);

Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);

startActivity(Intent.createChooser(share, "Share Image!"));
}

Unity:
AndroidJavaClass player = new AndroidJavaClass( "com.unity3d.player.UnityPlayer" );
AndroidJavaObject activity = player.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject javaClass = new AndroidJavaObject( "YourBundleName", activity );
javaClass.Call("ShareImage", "FilePath");

*Note : FilePath is your file location
*Note : Your Bundle Name  is like com.abc.123

沒有留言:

張貼留言