Unity Access Android sdk-Xiaomi SDK

Source: Internet
Author: User

Access The Android SDK process is divided into the following four steps:

1. Write Android activity file with Unity's call to Java Interface (Androidjavaclass/androidjavaobject)

2.Android Java code After writing, packaged into a jar package

3.copy Android Project to Unity

4.Android Callback Unity (Unityplayer.unitysendmessage)

One, write Android activity file with Unity's call Java interface

Android activity files are available in two ways:

1. Inheriting unityplayeractivity Android Java Code

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201711/03/d315f7938276dc5150bf8c5d06068d89.png-wh_500x0-wm_3 -wmp_4-s_1422347279.png "title=" image 1.png "alt=" D315f7938276dc5150bf8c5d06068d89.png-wh_ "/>

Unity's Call

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/03/f0a2725563a9b4009b2bba08c58a5cfa.png-wh_500x0-wm_3 -wmp_4-s_3712839070.png "title=" image 2.png "alt=" F0a2725563a9b4009b2bba08c58a5cfa.png-wh_ "/>

Androidjavaobject corresponding to Java's base class object, this class allows you to construct Java classes in Android directly from the class name in unity, which we typically use to make Android code calls
Androidjavaclass inheriting from Androidjavaobject, the relationship with it is equivalent to the relationship between object and class in Java, one is an instance of the class, and the other is the type of the class.

2. Use the current activity that unity itself is using Android Java Code

the Xiaomi SDK does not require us to create a separate activity, so we directly use the current activity that unity itself is using, just note that it is important to use Runonuithread to invoke it, otherwise it may not be possible to invoke it.

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/03/38bb40f24dedfc97b45181b2fe9f3a6e.png-wh_500x0-wm_3 -wmp_4-s_797531056.png "title=" image 3.png "alt=" 38bb40f24dedfc97b45181b2fe9f3a6e.png-wh_ "/>

Unity's Call

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/03/68bc9d8d3047a8ac0b76f16706a7e705.png-wh_500x0-wm_3 -wmp_4-s_3257622379.png "title=" image 4.png "alt=" 68bc9d8d3047a8ac0b76f16706a7e705.png-wh_ "/>

Second, after the Android Java code is finished, package it into a jar package mode 1: Below we learn how to invoke it in unity. First build the current Eclipse project, the code all of the. class files are generated in the Android Project Bin folder, the current project path is unitytestactivity->bin->classes-> Com->xys-> your. class file. The following need to package these. class files, Apple system to open the computer terminal, CD to the directory of the Classes folder, and then execute the codeJAR-CVF Class.jar * This line of code means that all the. class files in the current directory are packaged as. jar files, and the save file name is called Class.jar One thing that is particularly important in the appeal stepis that when you make a jar package, be sure to confirm that you want to generate a class file with R at the beginning of the path = =

such as these R files, these r files may cause your unity to fail the Android package because there is an R file in the Classer.jar package that comes with unity itself, and it will conflict with your R files.

Third, copy Android project to Unity1. Copy the res, asset from Android project to Assets\plugins\android

2. Copy the jar package and the corresponding SDK jar to Assets\plugins\android\bin

3. Set androidmanifest.xml

four:Android Callback Unity

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/03/614172068da891a76905c0cb895dfbf9.png-wh_ 500x0-wm_3-wmp_4-s_3392832867.png "title=" image 5.png "alt=" 614172068da891a76905c0cb895dfbf9.png-wh_ "/> 

The first parameter is Game object, so you need to bind the script on the player.
The second parameter is the method name defined in unity.
The third parameter is a parameter that defines the method (nullable).


This article is from the "13233523" blog, please be sure to keep this source http://13243523.blog.51cto.com/13233523/1978713

Unity Access Android sdk-Xiaomi SDK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.