Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. var r = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
  2. "getUserNames", "(V)Ljava/lang/String;");
  3. cc.log("Check this out" + r);
  4.  
  5. package org.cocos2dx.javascript;
  6.  
  7. import java.security.MessageDigest;
  8. import java.security.NoSuchAlgorithmException;
  9.  
  10. import org.cocos2dx.lib.Cocos2dxActivity;
  11. import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
  12. import android.content.pm.ActivityInfo;
  13. import android.content.pm.PackageInfo;
  14. import android.content.pm.PackageManager;
  15. import android.content.pm.Signature;
  16. import android.content.pm.PackageManager.NameNotFoundException;
  17. import android.net.wifi.WifiInfo;
  18. import android.net.wifi.WifiManager;
  19. import android.os.Bundle;
  20. import android.util.Base64;
  21. import android.util.Log;
  22. import android.view.WindowManager;
  23. import org.cocos2dx.plugin.PluginWrapper;
  24. import org.cocos2dx.plugin.FacebookWrapper;
  25. import android.content.Intent;
  26. import android.provider.Settings.Secure;
  27. import android.telephony.TelephonyManager;
  28. import android.util.Log;
  29.  
  30. // The name of .so is specified in AndroidMenifest.xml. NativityActivity will load it automatically for you.
  31. // You can use "System.loadLibrary()" to load other .so files.
  32.  
  33. public class AppActivity extends Cocos2dxActivity{
  34.  
  35. static String hostIPAdress = "0.0.0.0";
  36. // Get the instance of TelephonyManager
  37. TelephonyManager tm;;
  38.  
  39. // Calling the methods of TelephonyManager the returns the information
  40. static String IMEINumber;
  41.  
  42. @Override
  43. protected void onCreate(Bundle savedInstanceState) {
  44. // TODO Auto-generated method stub
  45. super.onCreate(savedInstanceState);
  46.  
  47. if(nativeIsLandScape()) {
  48. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
  49. } else {
  50. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
  51. }
  52. if(nativeIsDebug()){
  53. getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  54. }
  55. hostIPAdress = getHostIpAddress();
  56. IMEINumber = retrieveUserName();
  57. }
  58.  
  59. @Override
  60. public Cocos2dxGLSurfaceView onCreateView() {
  61. Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
  62. // TestCpp should create stencil buffer
  63. glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
  64.  
  65. PluginWrapper.init(this);
  66. PluginWrapper.setGLSurfaceView(glSurfaceView);
  67. FacebookWrapper.onCreate(this);
  68.  
  69. return glSurfaceView;
  70. }
  71.  
  72. public String getHostIpAddress() {
  73. WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
  74. WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
  75. int ip = wifiInfo.getIpAddress();
  76. return ((ip & 0xFF) + "." + ((ip >>>= 8) & 0xFF) + "." + ((ip >>>= 8) & 0xFF) + "." + ((ip >>>= 8) & 0xFF));
  77. }
  78.  
  79. public String retrieveUserName(){
  80.  
  81. tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
  82. String im = tm.getDeviceId();
  83. if (im == "") {
  84. im = Secure.getString(getContentResolver(),
  85. Secure.ANDROID_ID);
  86. }
  87.  
  88. return im;
  89. }
  90.  
  91. public static String getLocalIpAddress() {
  92. return hostIPAdress;
  93. }
  94. public static String getUserNames() {
  95. return IMEINumber;
  96. }
  97.  
  98. @Override
  99. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  100. super.onActivityResult(requestCode, resultCode, data);
  101. FacebookWrapper.onAcitivityResult(requestCode, resultCode, data);
  102. }
  103.  
  104. @Override
  105. public void onSaveInstanceState(Bundle outState) {
  106. super.onSaveInstanceState(outState);
  107. FacebookWrapper.onSaveInstanceState(outState);
  108. }
  109.  
  110. private static native boolean nativeIsLandScape();
  111. private static native boolean nativeIsDebug();
  112. }
  113.  
  114. var r = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
  115. "getUserNames", "(V)Ljava/lang/String;");
  116.  
  117. The code here
  118. (V)Ljava/lang/String;"
  119.  
  120. should be ()Ljava/lang/String;"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement