Unity access Android SDK

environment

SDK initialization

In the constructor of the MgAndroidSdkProcessorScript.cs script, InitBegin() is called to initialize the mgsdk and turn on the mask。 The onInitSdkResult method is called when the initialization result is returned

void InitBegin()
{
        MgSdkConfig config = new MgSdkConfig();
		//Configure the corresponding properties here
        config.AppKey = "0B51BDA9F7";//Required, apply identity
        config.CallbackId = "";//Optional, payment callback ID
        string s = config.toJson();
        mgSdkProcessor.initSDK(config);//Perform mgsdk initialization
}
void onInitSdkResult (String message)
{
//messageIs separated by commas”success,xxx,yyy,zzz”
       string param = "";//Additional parameters
      string result = parseMessage(message, out param); //Parsing Android messages
      if (result == "success")//Success returned, otherwise failure
      {
          isInit = true;
          showLogin();//Login window can be displayed here
      }
      else
     {
          Debug.LogError("Failed to initialize mgsdk:" + param);
      }
 }

Log in

You can call showLogin () to display the landing window in the initialization successfully callback onInitSdkResult.。 After successful login, the onLoginSuccess method will be called

void onLoginSuccess(String message)
{          
		//Close the mask after landing successfully. Users can play
		UIEventMaskEnd();
}

Payment

Where payment is needed, call Payment and pass in the parameter MgAndroidSdkProcessorScript.Instance.Payment(“Commodity key, Mg generated in the background "," user-defined data, can be order number”).

void onPaymentResult(String message)
{

	string param = "";//Additional parameters
      string result = parseMessage(message, out param); //Parsing Android messages
      if (result == "success")//Successful returnsuccess,Parsing Android messages
			Debug.LogError("Successful payment:" + param);                 
      }
      else
     {
          Debug.LogError("Failure to pay:" + param);
      }	 
	UIEventMaskEnd();  //Close the mask after payment failure. Users can play

 }

Export Unity as an Android project

  1. ClickFIle->Build Settings,Select Android platform in the pop-up box and click Switch Platform to switch。
  2. ClickPlayerSettings,In the right most inspector:
    1. Select Other Settings,change Minimum API Level to Android 5.0。Bundle identifier is set to a unique identifier, such as com.mguwp.testname
    2. Select Publishing Settings,Select Create New Keystore check box。
  3. Click build, select APK output directory, and save. Finally, put the generated APK into the mobile phone to run。

After successful payment, the server calls back to the developer server