Cocos2d-js Call Java__java

Source: Internet
Author: User

Js:

Call the Hello method
    jsb.reflection.callStaticMethod ("Org/cocos2dx/javascript/test", "Hello", "(ljava/lang/string;) V" , "This is a message from JS");

Call the first sum method
    var result = Jsb.reflection.callStaticMethod ("Org/cocos2dx/javascript/test", "Sum", "(II) I", 3, 7);
    Cc.log (result);

Call the second sum method
    var result = Jsb.reflection.callStaticMethod ("Org/cocos2dx/javascript/test", "Sum", "(i) I ", 3);
    Cc.log (result); 5


    var udid = Jsb.reflection.callStaticMethod ("Org/cocos2dx/javascript/test", "Udid", "() ljava/lang/string;");
    Cc.log ("UDID ==>" + UDID);

Java:Test.Java

/**************************************************************************** Copyright (c) 2015 Chukong
 
Technologies INC. Http://www.cocos2d-x.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software a D Associated documentation files (the "Software"), to deal in Software without restriction, including without On the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to MIT persons to whom the Software are furnished to does so subject to the following conditions:the copyright above a

ND this permission notice shall is included in all copies or substantial of the portions. The SOFTWARE is provided ' as is ', without WARRANTY of any KIND, EXPRESS OR implied, including BUT not LIMITED to the Warra Nties of merchantability, FITNESS for A particular purpose and noninfringement. In NO EVENT SHALL the AUTHORS OR COPYRIGHT holders is liable for any CLAIM, damages OR other liability, WHETHER in a ACTION of CONTRACT, TORT OR Otherwise, arising from, out of OR in CONNECTION with the SOF
Tware or the use or other dealings in the SOFTWARE.

/package org.cocos2dx.javascript;
Import Android.content.Context;
Import Android.net.wifi.WifiInfo;
Import Android.net.wifi.WifiManager;

Import Android.telephony.TelephonyManager;

Import com.google.android.gms.common.api.GoogleApiClient;
Import org.cocos2dx.lib.Cocos2dxActivity;


Import Org.cocos2dx.lib.Cocos2dxGLSurfaceView; public class Appactivity extends Cocos2dxactivity {/** * attention:this is auto-generated to implement the Ap
     P Indexing API.
     * Https://g.co/AppIndexing/AndroidStudio for more information.
    * Private Googleapiclient client;
     /** * Attention:this is auto-generated to implement the APP indexing API.
     * Https://g.co/AppIndexing/AndroidStudio for more information. */Private Googleapiclient Client2; @Override public Cocos2dxglsurfaceview Oncreateview () {Cocos2dxglsurfaceview Glsurfaceview = new COCOS2DXGLSU
        Rfaceview (this);

        Testcpp should create stencil buffer Glsurfaceview.seteglconfigchooser (5, 6, 5, 0, 16, 8);
    return glsurfaceview; The composition of/** * DeviceID is: Channel sign + identifier source flag +hash after the terminal identifier * <p/> * Channel sign is: * 1,ANDRIOD (a) * <p/&
     Gt * Identifier SOURCE Logo: * 1, WiFi MAC address (WiFi); * 2, IMEI (IMEI); * 3, serial number (SN); * 4, ID: Random code.
     If the front is not taken, then randomly generated a random code, need to cache. * * @param context * @return/public static String UDID () {StringBuilder deviceId = new St
        Ringbuilder ();

        Channel sign Deviceid.append ("a"); try {//WiFi MAC address Wifimanager WiFi = (wifimanager) getcontext (). Getsystemservice (Context.wifi_se
            Rvice);
            Wifiinfo info = Wifi.getconnectioninfo (); String Wifimac = info.geTmacaddress ();
                if (!wifimac.isempty ()) {deviceid.append ("WiFi");
                Deviceid.append (WIFIMAC);
            return deviceid.tostring (); //IMEI (IMEI) Telephonymanager TM = (Telephonymanager) getcontext (). Getsystemservice (Context.te
            Lephony_service);
            String IMEI = Tm.getdeviceid ();
                if (Imei.isempty ()) {deviceid.append ("IMEI");
                Deviceid.append (IMEI);
            return deviceid.tostring ();
            }//serial number (SN) String sn = Tm.getsimserialnumber ();
                if (!sn.isempty ()) {deviceid.append ("sn");
                Deviceid.append (SN);
            return deviceid.tostring ();
        } catch (Exception e) {e.printstacktrace ();
    return deviceid.tostring ();
 }
}

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.