Unity - Share Text Message / Game Link To Other Apps In Android

Adding the capability to Send Text Data from our game to other Android apps will drastically increase the number of downloads that our app / game gets. Wonder how? Well, we will add the Share App feature to our game with a single click of a button and there you go, it definitely helps your users to share your game among their friends (on WhatsApp, Facebook, Gmail, Twitter and what not!) easily.
We will demonstrate how to add the feature in this short post of ours.

Create a new C# Script named ShareApp and attach it to the Main Camera. Open the script and paste the following content to it

using UnityEngine;
using System.Collections;


public class ShareApp : MonoBehaviour {
 
 string subject = "WORD-O-MAZE";
 string body = "GAME LINK HERE + DESCRIPTION";

 public void shareText(){
 //execute the below lines if being run on a Android device
 #if UNITY_ANDROID
  //Refernece of AndroidJavaClass class for intent
  AndroidJavaClass intentClass = new AndroidJavaClass ("android.content.Intent");
  //Refernece of AndroidJavaObject class for intent
  AndroidJavaObject intentObject = new AndroidJavaObject ("android.content.Intent");
  //call setAction method of the Intent object created
  intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
  //set the type of sharing that is happening
  intentObject.Call<AndroidJavaObject>("setType", "text/plain");
  //add data to be passed to the other activity i.e., the data to be sent
  intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), subject);
  intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), body);
  //get the current activity
  AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
  AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
  //start the activity by sending the intent data
  currentActivity.Call ("startActivity", intentObject);
 #endif
  
 }
 
} 

Save the script and switch to Unity. Create a Unity Button and call the function shareText, onClick of the button.

Share App / Text - Unity Android

Once you build this, you will see something like the below screenshot, from our game, when you click on the Share Text button.

Share App / Text - Unity Android

See you around.
Share on Google+

About Unknown

Sujit Horakeri is a game freak just like any other next door guy you would come across. He is a Web Developer by Profession, Game Developer by Choice.
    Blogger
    Facebook

58 comments:

  1. Hi Sujit, how can i send a text with an image? thanks!

    ReplyDelete
  2. I am curious why yours shows as "Share Via" and then asks the user to choose an app and mine shows like this. http://i.imgur.com/NZjQh9s.png

    I would like to remove the "Just once" and "Always" part and force it to always ask the user what app to share with. Any ideas? Thanks

    ReplyDelete
    Replies
    1. Share Via is shown when you are sharing any app or content for the first time. If you have shared a content using, say twitter, the last time, that will be populated first. Regardless, you can choose other apps to share the content.
      As far as clearing this selection is concerned, I'm not sure as to where this can be done. I'll let you know once I figure it out.

      Delete
  3. Hi Sujit, I have tried your script but it's not share my text on Facebook.

    ReplyDelete
    Replies
    1. For Facebook you need to download the FB Unity SDK and then use their methods. facebook has ots security it won't allow to share without login.

      Delete
  4. thank you so much for this script, very helpful : )
    just one question, how can i have the same functionality in ios?
    any suggestion? thank you!

    ReplyDelete
  5. Hey it is useful but why it is not sharing text on Facebook ???
    Whats the way to share link to facebook ...

    ReplyDelete
    Replies
    1. https://www.facebook.com/sharer/sharer.php?u=" + System.Uri.EscapeUriString(PlayStoreLink)

      Delete
    2. Add your app link like , it will work on fb too

      string body ="https://play.google.com/store/apps/details?id=com.Infocom.Teen_Patti";

      Delete
    3. Add your app link like , it will work on fb too

      string body ="https://play.google.com/store/apps/details?id=com.Infocom.Teen_Patti";

      Delete
  6. What about IOS please? share text on IOS through unity game

    ReplyDelete
  7. Thank u so much ! this was very helpful . but is there any way by which i can check if the user has actually shared the text or not ?

    ReplyDelete
    Replies
    1. You can check if the user has clicked the button through which you are sharing the text. Set a playerprefs flag and assign true when that button is pressed. But then there will be cases when the user has pressed the button and not really shared it.

      Delete
  8. working but in facebook share, text box is empty not getting text from script.

    I from unitydiy blog

    ReplyDelete
    Replies
    1. Add your app link like , it will work on fb too

      string body ="https://play.google.com/store/apps/details?id=com.Infocom.Teen_Patti";

      Delete
  9. I am having a weird problem...when i share my game on gmail or messaging it perfectly works...but in facebook it did not work...
    my link is this--https://play.google.com/store/apps/details?id=com.Crea2rsGameStudio.control


    but in fb it becomes this---https://play.google.com/store/apps/details?id=com.Crea2rsGameStudio.control%29


    plz help me...why it is happening

    ReplyDelete
  10. i have a question i am able to share an image with text but when i trie different apps it behaves differently eg on whatsapp it takes the image with the text if i tried facebook just takes the image without text please help

    ReplyDelete
  11. hi
    can i set defult app for sharing??
    i don’t want user choose desired app for sharing. i want just share my game via whatsapp.
    thanks

    ReplyDelete
  12. can anyone help me about ios???
    i want share my game in ios.

    ReplyDelete
  13. This is amazing tutorial. Thanks Sujit Horakeri.

    ReplyDelete
  14. The new Samsung Galaxy Note 8 will hopefully avoid the fiasco that was the bane of the Galaxy Note 7. With the Korean giant looking to recoup its multi-billion dollar losses, we have created a wishlist of the features which will be seen on the Samsung Galaxy Note 8. We are waiting with baited breath the release of the new device. Galaxy Note 8 Wishlist

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. Thanks for above information, I like it. check it once Android Online Training Hyderabad

    ReplyDelete
  17. I want to share my game link only on WhatsApp at a single tap....plz help me

    ReplyDelete
  18. Rajasthan Royals will kick-off their season with an away fixture against Sunrisers Hyderabad on April being unfaithful, followed by a home game against Delhi Daredevils on April 11 at Sawai Mansingh Stadium in Jaipur.
    Kolkata Knight Riders – KKR 2018 Schedule & Tickets
    Buy RCB 2018 Jersey From Amazon & Flipkart

    ReplyDelete
  19. good luck i always check your blog roz

    ReplyDelete
  20. I am happy to find this post Very useful for me, as it contains lot of information

    Android Training Institute in Chennai

    android classes in chennai

    ReplyDelete

  21. The UFC initially planned an abysmal title bout between Nurmagomedov in addition to The Ultimate Fighter: Team Lesnar vs. Team dos Santos welterweight winner Tony Ferguson, howeverit was canceled due to the Russian with medical issues connected with his weight reduction weigh-in day.Ferguson eventually won the interim title at UFC 216 against Kevin Lee.Ferguson was subsequently expected to fulfill Nurmagomedov in UFC 223, along with the winner being crowned the undisputed winner (because McGregor could be stripped off of this title whenever the bout happened ). Subsequently, it was scrapped once more (fourth moment ) since Ferguson got hurt, and after a few chances to get an opponent, Nurmagomedov eventually won the vacant title against Al Iaquinta. [9] [10] This card has been marked by an attack on a bus containing lots of fighters scheduled to compete in case (such as Nurmagomedov and 2 teammates), ran by McGregor and his team.

    Jussier Formiga was scheduled to confront Sergio Pettis in January 2017 in UFC Fight Night: Rodríguez vs. Penn.. However, Formiga pulled out of this struggle for undisclosed reasons.The pairing was rescheduled for this particular occasion.
    https://ufc229fightlive.com/

    ReplyDelete
  22. Perhaps you have finished to this? Well, now arrive in the following step.Gradually, I will take you to the limitation to finish it quickly. Now grab your telephone and swap the candy and try to wash all the icing. This individual move is very likely to produce the ample space so that you can quickly produce unique candies. Along
    Puzzle out to make the specific candies as many as possible. The individual candy is your trick to maneuver the amount economically and quickly. Candy Crush

    ReplyDelete
  23. Your website is really cool and this is a great inspiring article. best backlinks

    ReplyDelete
  24. When there you get a chance attempt to coincide with all the candy close to the bottom of the area. By making this motion likely, you may produce the chance to change a substantial variety of candy. Normally, this produces frequently a chain reaction, and in the Crash video game, the show response usually means a lot of chances to locate the free unique candy. Candy Crush

    ReplyDelete
  25. During this website, you will see this shape, i highly recommend you learn this review.
    https://qualityseopackages.com/qspx-managed-whitelabel-seo-services/

    ReplyDelete
  26. here is my great offer i will provide you 80 niche relevant hight quality blog comments with high authorize sites good for your website rank your site on google, bing, yahoo etc. All comments are manually No software use. 80 niche relevant blogcomment

    ReplyDelete
  27. As search engines can be considered the largest online sources for delivering traffic to web sites, there are hundreds and thousands of online resources, which offer a great pdf submission service of search engine pdf books, articles, manuals, etc. for the newbies covering hot topic of generating web site traffic and boosting your online income. In this article I would like us to take a closer look at such products, their availability and worth.

    ReplyDelete
  28. Just admiring your work and wondering how you managed this blog so well. It’s so remarkable that I can't afford to not go through this valuable information whenever I surf the internet!  Plagiarism checker

    ReplyDelete
  29. I felt very happy while reading this site. This was really very informative site for me. I really liked it. This was really a cordial post. Thanks a lot!.
    BUY WEBSITE TRAFFIC

    ReplyDelete
  30. These days everyone knows how to get backlinks. Website owners are niche blog commentsthe link building process for a very lower cost. If you are an online marketer, you need to think and act differently.

    ReplyDelete
  31. This article pertains to a potential usability issue of using niche backlinksfiles on a website and offers suggestions on how to prevent this from happening.

    ReplyDelete
  32. Jumpy Frog free android games download now .Jumpy Frog

    ReplyDelete
  33. The significant positive data for IMO APK Beta for Android has the straightforward structure video calls, so you can undoubtedly deal with the calls. There is no restriction can be accessible for the profile and ring tomes. IMO APK

    ReplyDelete

  34. How To Move Candy Crush 1879 Amount In 10 Minutes.

    Now I shall talk with you about licorice luna episode in Candy crush 1879 level.Candy crush 1879 degree is carbonated luna incident .The amount has more rules and condition. So in the event it's the case that you do not know about the level, never you move on the level. You'll find 27 fewer or moves, six blockers four to 5 colours, just 59 spaces, required 10,000 factors just. 75 icing ply need to amass.

    The yellowish Sweets also have to collect .there are just four Colors like orange, green bluepurple. The first target is 10000 factors and then 20000 points along with finally 30000 factors. When you reach 3000 things you will gather 3 stars and pass the degree .the yellowish colour candy are extremely considerable within the level because your game rides on the 3 yellowish sweets. The 3 yellowish sweets see in conveyer buckle if you're lucky. But if you are unlucky one or 2 yellowish candy you will see.

    The Plan of the level of all 1879 is poor at additional match Where lucky candy become like but this match the lucky candy became yellow candy so that you will endeavour to get lucky candy.

    The object of candies Establish 1879 degree

    The degree is ginger luna episode.

    You will find 27 motions or six and fewer blockers

    4 to 5 colours

    Only 5-9 distances

    Seventy Five icing ply

    Perform with a Critical part in yellowish candies

    • 1st will possess To achieve 7800 points and also to get one particular start you also produce 2200 details. So that your main aim is 10000 factors

    • For 2 begins You must amass 20000 factors

    • Eventually, to Achieve three begins, you must collect 30000 details
    candy crush level 130

    ReplyDelete
  35. Thank you for sharing a bunch of this quality contents, I have bookmarked your blog. Please also explore advice from my site. I will be back for more quality contents. Lexis Poker

    ReplyDelete
  36. Well, that is most certainly good, however think about the additional options we now have here? Would you brain creating another post regarding these too? Respect! Pest Control Companies in Abu Dhabi

    ReplyDelete
  37. It should be noted that whilst ordering papers for sale at paper writing service, you can get unkind attitude. In case you feel that the bureau is trying to cheat you, don't buy term paper from it. Jumpy Frog

    ReplyDelete
  38. This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this.. Jumpy Frog

    ReplyDelete
  39. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. buy backlinks

    ReplyDelete
  40. I like your post. It is good to see you verbalize from the heart and clarity on this important subject can be easily observed... Blog Commenting Packages

    ReplyDelete