Send SMS From Your Game - Unity3D

Last updated : May 10, 2017

Posted by: 6

In the game, you can use "prefer the game" feature or invite the friend(s) who is not using the game. Then you can send friends the SMS with game information.

For achieving this, you have to attach the SendSMSClass class to your active game object & use 

- sendSingleSMS() - for sending SMS to single recipient &

- sendMultipleSMS() - for sending SMS to multiple recipients.

This functions will open the default native SMS app with pre-filled recipient mobile number(s) & body massage, which we passed from the method.


Code:

- using System.Collections;

- using System.Collections.Generic;

- using UnityEngine;


public class SendSMSClass : MonoBehaviour {


   //recipient's mobile number

    string sender_mobile_numner = "8866509166";

    //recipient's mobile number array

    string[] sender_mobile_number_array = new string[]{"8866509166","9898071856"};

    string sms_body = "Your sms body";


   //for sending SMS to single recipient

    public void sendSingleSMS(){    

       //Open the native SMS default app

        Application.OpenURL(string.Format("sms:"+sender_mobile_numner+"?body="+sms_body));

    }


   //for sending SMS to multiple recipients

    public void sendMultipleSMS(){

        sender_mobile_numner = "";

        foreach(string mobile_number_str in sender_mobile_number_array)

            sender_mobile_numner += mobile_number_str + ";";

            

       //Open the native SMS default app

        Application.OpenURL(string.Format("sms:"+sender_mobile_numner+"?body="+sms_body));

    }


   void OnGUI() {

        if (GUI.Button (new Rect (10, 10, 250, 50), "Send SMS to single recipient"))

            sendSingleSMS ();

        else if (GUI.Button (new Rect (10, 70, 250, 50), "Send SMS to multiple recipient"))

            sendMultipleSMS ();

    }

}


This code will be useful for Android & iOS game.

Also, see the attachments for APK & Project sample.



Send SMS From Your Game - Unity3D

Send SMS From Your Game - Unity3D

In the game, you can use "prefer the game" feature or invite the friend(s) who...
Send Email From Your Game - Unity3D

Send Email From Your Game - Unity3D

In your game, it might be possible that user directly wants to send an email to...
Reduce a size of APK and IPA – Unity 3d

Reduce a size of APK and IPA – Unity 3d

For reducing APK size:In Unity 5.6.0f3 I have created a simple "Hello world"...
Unity3D vs. Cocos2DX

Unity3D vs. Cocos2DX

License: Unity 3D is paid while Cocos2DX is an open-source game...
You will be amazed to know that these 5 games are developed with Unity 3D

You will be amazed to know that these 5 games are developed with Unity 3D

1. Pokémon GODeveloped & published by Niantic; when both Niantic &...
Integrate Banner Ad for iOS & Android using AdMob

Integrate Banner Ad for iOS & Android using AdMob

Requirements- Unity 4 or higher- To deploy on iOS     ...
Integrate Interstitial Ad for iOS & Android using AdMob

Integrate Interstitial Ad for iOS & Android using AdMob

Requirements- Unity 4 or higher- To deploy on iOS       -...
Submit a Game to AppStore - For beginners

Submit a Game to AppStore - For beginners

Steps to submit a Game to AppStore1. Switch platform as iOS and then make a...
Use Debug.Break() to pause the editor

Use Debug.Break() to pause the editor

Use Debug.Break() in your code to pause the editorDid you know that you can...