Unity adds multiple Android SDKs to resolve conflicts

Source: Internet
Author: User

Unity calls the Android method on the web there are many, here is not to repeat, but when we call ANDROIDSDK, is generally inherited unityplayeractivity, and then we start from the mainactivity of our SDK.

So the question is, how do we execute our SDK without modifying the Java file If we have already added Unity's SDK and it has inherited unityplayeractivity?

Idea: Get the Unityplayeractivity class in C # and pass it as a parameter into the method.

1 Unity:2 ```3Androidjavaclass Unity =NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer");4Androidjavaobject unityactivity = Unity. Getstatic<androidjavaobject> ("currentactivity");5     using(Androidjavaobject Jo =NewAndroidjavaobject ("Com.klondike.solitaire.spider.Classic.SDKBridge"))6     {7Jo. Call ("Plugincall", unityactivity);8Debug.Log ("Call the Android method");9     }Ten Java: One  Public voidPlugincall (activity activity) A     { -LOG.D ("Plugincall","callalllll"); -     } the      - this way, you can start the relevant SDK directly without having to modify it in Mainactivity - ``` - Android Terminal + ``` - Mainactivity.java +  Public voidshowmsg (Activity activity,string msg) A     { atIntent Intent =NewIntent (Activity.getbasecontext (), HelloWorld.class); -Intent.putextra ("type", msg); - activity.startactivity (intent); -     } -      - Helloworld.java in  Public classHelloWorld extends Activity - { to @Override +     protected voidonCreate (Bundle savedinstancestate) { - super.oncreate (savedinstancestate); the //Setcontentview (r.layout.activity_main); * //TextView showmsg = (TextView) Findviewbyid (r.id.android_show); $String type = This. Getintent (). Getstringextra ("type");Panax Notoginseng //showmsg.settext (type); -     } the } +```

Unity adds multiple Android SDKs to resolve conflicts

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.