16

Social Sharing Tutorial (Unity, Android) (Code)

This post contains all the code that’s been written in the YouTube video.

You can read it at your own pace, although watching the video prior to looking at this code example is recommended.

NativeShareScript.cs

 

Matej
 

Matej is an app developer with a knack for teaching others. If he's not programming, making tutorials or doing other business, he's mostly working out, listening to audiobooks and taking cold showers.


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    radhe says:

    hi
    your code working well but
    when i post on facebook not ganaracter app link
    please solve my problem

    thanks

    • Hello!
      I’d like to help but you must’ve misspelled “ganaracter” so I don’t know exactly what you’re asking about.


      • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
        radhe says:

        hello,

        when i post on Facebook not sharing app link
        how to share 2 link in one post on Facebook?
        how to share both image and link in one post on Facebook?

        thanks


        • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
          Bell says:

          i have the same problem, can you tell me if you resolve it. thank you.


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    Swapnil says:

    Sharing link on facebook is not allowed.


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    vijay says:

    hey I’m vijay and I’ve pasted and done exactly as shown in youtube tutorial but I got an caution error i.e : : tiled GPU pref. warning : Render Texture colour surface (480 x 854) was not cleared/discarded, doing camera.renderer/Camera.ImageEffects.
    plz help I’m stuck here hope u reply very soon, anyway thnx.


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    turkoz says:

    Hi, im using you tutorial and trying to develop a video sharing but when i try to upload/share on youtube the video has an error or something like that and dont appear.

    IEnumerator ShareScreenshot()
    {
    isProcessing = true;

    if (!Application.isEditor)
    {
    AndroidJavaClass intentClass = new AndroidJavaClass(“android.content.Intent”);
    AndroidJavaObject intentObject = new AndroidJavaObject(“android.content.Intent”);
    intentObject.Call(“setAction”, intentClass.GetStatic(“ACTION_SEND”));
    AndroidJavaClass uriClass = new AndroidJavaClass(“android.net.Uri”);
    AndroidJavaObject uriObject = uriClass.CallStatic(“parse”, “file://” + savedPath);
    intentObject.Call(“putExtra”, intentClass.GetStatic(“EXTRA_STREAM”),
    uriObject);
    intentObject.Call(“putExtra”, intentClass.GetStatic(“EXTRA_TEXT”),
    “#test”);
    intentObject.Call(“setType”, “video/mp4”);
    AndroidJavaClass unity = new AndroidJavaClass(“com.unity3d.player.UnityPlayer”);
    AndroidJavaObject currentActivity = unity.GetStatic(“currentActivity”);
    AndroidJavaObject chooser = intentClass.CallStatic(“createChooser”,
    intentObject, “Share video.”);
    currentActivity.Call(“startActivity”, chooser);

    yield return new WaitForSecondsRealtime(1);
    }

    isProcessing = false;
    }


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    duchan says:

    Dik za zdrielanie 😉


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    Leandro says:

    Hi,

    Great tutorials as always.

    What if I wanted to share only a predefined image instead of a screen shot?
    I would like that by clicking the share button, the icon of my game would be shared with his link from the PlayStore. I tried to make some changes to your code, but it did not work. I am a beginner in C # and would be very grateful if you could answer me how.

    Regards


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    Shubham Prakash says:

    very nice Thank you so much


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    Ravin says:

    is this code working for Android Oreo and above ?


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    Santosh says:

    Hi ,
    I tried to integrate sharing functionality in my APP.
    I followed your YouTube tutorial and code , but it seem like my sharing options are not appearing.
    I want to know that where am going wrong.
    Sorry in Advance for bad english

    Regards ,
    Santosh


  • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
    Mike says:

    Any idea why this code works if I share to WhatsApp but doesn’t work if I share to discord App? It gives me a “A bad network request has occurred, please try again”
    error every time.


    • Notice: Trying to get property of non-object in /home/resocode/public_html/wp-content/plugins/thrive-comments/includes/class-thrive-comments-front.php on line 540
      Mike says:

      It works if I remove the picture when in confirmation screen in discord…

  • >