Talk about unity calling Android's activity

Source: Internet
Author: User

This time in the study of the Unity4.3 development environment, how to invoke the activity written by Android SDK4.4.2. Refer to a lot of online blog, Baidu out of the dozens of most are reproduced rain pine Momo, here must be to the rain Pine Momo pay tribute! But the rain Momo write blog is too old, a lot of content is outdated, I strictly according to his steps, or a problem, so this blog is to tell everyone in the unity4.3+android SDK4.4.2 environment, start activity details.

My blog will not start from scratch, so first give two important links, you should look at:

The first one is the Rain Pine Momo http://www.xuanyusong.com/archives/667 The concept of this blog is correct, but the process has passed

The second one is a relatively new blog http://www.narkii.com/club/thread-320335-1.html the concept and operation of this blog is correct, but the details are omitted, the focus is not clear, my blog is to add to it.


Steps:

1: Open Eclipse, create an Android project, Note that either create the library at the time of creation, or select the IS library after creating the project properties on the Android page.

2: In the project properties of Java Build path-Libraries, with the Add External jars button, add unity Classes.jar, such as my unity is mounted on the D disk, the path is: D:\Program Files\unity\editor\data\playbackengines\androidplayer\development\bin.

3: Write two activity,a and B, implement start B in a. This process can refer to the above recommended blog, they are very detailed, I just emphasize thata need to inherit from Unityplayeractivity, and B only inherit from the activity.

4: Compile Android project, will generate a Xxx.jar file in the bin directory, note that this jar only about 2k size is not available , because many classes are not included in, such as important r.layout.class. After compiling, the export must be used and the correct package will be selected to generate a jar of 100-600k size, which is Momo not to speak. Here are the package items that I selected:


5: At this point, the Android section is basically OK. Open Unity to create a project, under Assets\plugins\android, copy the jar you just generated, plus the Res folder.

6: go to Unity's installation directory under D:\Program files\unity\editor\data\playbackengines\androidplayer Locate the Androidmanifest.xml, copy it to the Unity Project's assets\plugins\android directory , and then modify it with two places to change, 1 to change the package name to your Android project, and 2 to <activity android:name= This equals to the name of your Android project's main activity, like mine:

<manifest
Xmlns:android= "Http://schemas.android.com/apk/res/android"
package= "Com.example.unitytestactivity"
android:installlocation= "Preferexternal"
Android:theme= "@android: Style/theme.notitlebar"
Android:versioncode= "1"
Android:versionname= "1.0" >

..........

..........

<activity android:name= ". Unitytestactivity "
Android:theme= "@android: Style/theme.notitlebar.fullscreen"
Android:configchanges= "fontscale|keyboard|keyboardhidden|locale|mnc|mcc|navigation|orientation|screenlayout| Screensize|smallestscreensize|uimode|touchscreen ">

Note the point before the name. The second sentence indicates that the title does not appear on startup, and this problem has been frustrating me for a long time. The third sentence is directly copied.

7: Write Unity under the script CS file, here is nothing to say, refer to the Rain Pine Momo.

8:unity Build setting Notice to change the bundle identifier to your Android project's package name.

9: Note that the ability to start an activity from unity cannot be simulated in unity, it must be installed in the real machine to see the effect , I have been silly and depressed to try for a long time. It is estimated that subsequent unity releases will improve the problem.

Related Article

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.