Unity Android SDK Comments

A Glossary

(1) SDK: a set of software development kit (Software Development Kit) application software development tools

(2) JDK: Java development tools, the main provider of basic libraries, Java compiler, runtime JVM (Java Virtual Machine), debugger, etc.

  https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

(3) JRE: Java Runtime Environment (Java Runtime Environment) Java Runtime Environment, when a part of the JDK

   

 

(4) Android SDK: Software Development Kit Andrews, on the basis of added additional JDK class library android.jar, Android provides a virtual machine DVM and ART

(5) JNI: Java Native Interface JNI is the Java Native call a specification language, you can make Java and C / C ++ models interact through JNI

(6) NDK: The official explanation Native Develp Kit as follows: Android NDK is a set that allows you to use native code languages ​​(such as C and C ++) implementation tool set some of the features, in short, Android besides Java can be used to achieve, part can be done with C ++, NDK does not depend on Dalvik Java virtual machine

      NDK is mainly the Native language is compiled into a dynamic link library (.dll files, .so file, .jnilib)

(7) .NET: Microsoft .NET Framework, .NET technology framework consisting of specific implementation in the Windows system, in short the equivalent of Java jdk, that is the most basic development package, the most basic framework

(8) Mono: .net framework is an open source, cross-platform, not Microsoft's products, it is also composed of mono mono compiler and run-time

(9) IL: .NET code into the machine language into an intermediate language, the code that is compiled after .NET does not generate direct machine language, but will become Mr. IL, similar to assembly code

Two main components Android program

(. 1) the AndroidManifest.xml: Unity path corresponding to Assets / Plugins / the AndroidManifest.xml   the Android manifest file containing the application name, icon, package name, the four assembly modules, permissions

(6) libs: correspondence Unity path Assets / Plugins / Android stored inside a jar and class libraries written in Java aar

(7) src / main / assets: Unity path corresponding to Assets / StreamingAssets external resources
(8) src / main / Java: Java Code
(9) src / main / jniLibs: c ++ library compiled so
(10) src / main / res: Android Resource Files
 

Unity call three Android

 

(1) AndroidJavaClass is a general representation of instances of java.lang.Class Unity

(2) AndroidJavaObject are generic examples of java.lang.Object representation Unity

 

example:

 

 

 

 (3)Activity和UnityPlayerActivity

https://www.jianshu.com/p/476087b4c087

 

 UnityPlayerActivity is the default unity Android package Activity

(4)application

 

 

 

application can be inherited, the following is an example

 

 Then referenced in the androidmanifest

 

(5) android code calls a function of Unity

UnityPlayer.UnitySendMessage(string gameObject, string runtimeScript, string arg);

 

Four examples of mobile MM

 application

package com.xx.Racing;
import android.app.Application;
import android.content.Context;
import com.secneo.sdkp.DexHelper;

public class MMApplication
  extends Application
{
  protected void attachBaseContext(Context ctx) {
    super.attachBaseContext(ctx);
    DexHelper.install(this, "mmbilling.3.1.8.jar.protected.jar");
  }
}

  

AndroidforUnity to the library unity call

package com.mm.payforunity;

import android.content.Context;
import mm.purchasesdk.Purchase;

public class PayForUnity
{
  private static final String APPID = "300009265921";
  private static final String APPKEY = "065DF5E770AE73C7ECDE5EE7FA174999";
  private static IAPListener listener;
  
  public static void InitSDK(Context context, String gameObject, String runtimeScript) {
    try {
      Purchase.getInstance().setAppInfo("300009265921", "065DF5E770AE73C7ECDE5EE7FA174999");
    }
    catch (Exception e1) {
      
      e1.printStackTrace();
    } 
    listener = new IAPListener(context, gameObject, runtimeScript);   
    try {
      Purchase.getInstance().init(context, listener);
    }
    catch (Exception e) {
      
      e.printStackTrace();
    } 
  } 
  public static void doPay(Context context, String paycode) {
    try {
      Purchase.getInstance().order(context, paycode, 1, listener);
    }
    catch (Exception e1) {
      
      e1.printStackTrace();
      return;
    } 
  }
}

  

Androidmanifest

<manifest android:versionName="1.0" android:versionCode="1" package="com.gzzhengyou.Racing" xmlns:android="http://schemas.android.com/apk/res/android">

<supports-screens android:anyDensity="true" android:xlargeScreens="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>

<application android:label="@string/app_name" android:icon="@drawable/app_icon" android:name="com.xx.Racing.MMApplication">

<activity android:label="@string/app_name" android:name="com.xx.Racing.UnityPlayerNativeActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:screenOrientation="landscape">

<intent-filter>

<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>

</intent-filter>

</activity>

</application>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<uses-permission android:name="android.permission.SEND_SMS"/>

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

</manifest>

  

unity call Android

using UnityEngine;
using System;
using System.Collections.Generic;

public class MMBillingAndroid
{
#if UNITY_ANDROID

    private AndroidJavaClass klass = new AndroidJavaClass("com.mm.payforunity.PayForUnity");

    private static MMBillingAndroid _instance;
    public static MMBillingAndroid Instance
    {
        get
        {
		if(_instance==null){
                  _instance = new MMBillingAndroid();
		}
            return _instance;
        }
    }
	public void InitSDK(String gameObject, String runtimeScript)
	{
		AndroidJavaClass unityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
		AndroidJavaObject curActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
		curActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
        {
            klass.CallStatic("InitSDK", curActivity, gameObject, runtimeScript);
        }));
	}

    public void doPay(string paycode)
    {
        AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject curActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
        curActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
        {
            klass.CallStatic("doPay", curActivity, paycode);
        }));
    }
#endif
}

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

    

Guess you like

Origin www.cnblogs.com/July7th/p/11832549.html