Share pictures and text to friends in the Android app

Source: Internet
Author: User

Share pictures and text to friends in the Android app

 


You need to add the permission to read and write sdcard to the configuration file.

 

Using UnityEngine; using System. collections; using System. IO; public class Share: MonoBehaviour {public static string imagePath; static AndroidJavaClass extends pluginclass; static AndroidJavaClass unityPlayer; static AndroidJavaObject currActivity; private static Share mInstance; public static Share instance {get {return mInstance ;}} void Awake () {mInstance = this;} void Start () {imagePath = Application. persistentDataPath +/HKeyGame.png; export pluginclass = new AndroidJavaClass (com. ari. tool. unityAndroidTool); if (export pluginclass = null) {Debug. log (writable pluginclass is null);} else {Debug. log (writable pluginclass is not null);} unityPlayer = new AndroidJavaClass (com. unity3d. player. unityPlayer); currActivity = unityPlayer. getStatic (currentActivity);} public void CallShare (string handline, string subject, string text, bool image) {Debug. log (share call start: + imagePath); if (image) {sharePluginClass. callStatic (share, new object [] {handline, subject, text, imagePath});} else {shareinclass. callStatic (share, new object [] {handline, subject, text,});} Debug. log (share call end);} public void ScreenShot () {StartCoroutine (GetCapture ();} IEnumerator GetCapture () {yield return new WaitForEndOfFrame (); int width = Screen. width; int height = Screen. height; Texture2D tex = new Texture2D (width, height, TextureFormat. RGB24, false); tex. readPixels (new Rect (0, 0, width, height), 0, 0, true); byte [] imagebytes = tex. encodeToPNG (); // convert to png graph tex. compress (false); // compresses the screen cache // image. mainTexture = tex; // display the screen cache (thumbnail) File. writeAllBytes (Application. persistentDataPath +/HKeyGame.png, imagebytes); // stores the png Image Debug. log (Application. persistentDataPath );}}


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.