private static void BurstlyCurrencyWrapper_initialize(string publisherId, string userId)
 {
     jvalue[] args = new jvalue[2];
       		args[0].l = AndroidJNI.NewStringUTF(publisherId);
       		args[1].l = AndroidJNI.NewStringUTF(userId);
         AndroidJNI.CallStaticVoidMethod(BurstlyPluginClass, methodID_initialize, args);
 }
 private static void BurstlyCurrencyWrapper_increaseBalance(string currency, int amount)
 {
     jvalue[] args = new jvalue[2];
       		args[0].l = AndroidJNI.NewStringUTF(currency);
       		args[1].i = amount;
         AndroidJNI.CallStaticVoidMethod(BurstlyPluginClass, methodID_increaseBalance, args);
 }
		public static IntPtr NewProxyInstance(int delegateHandle, IntPtr interfaze)
		{
			jvalue[] array = new jvalue[2];
			array[0].i = delegateHandle;
			array[1].l = interfaze;
			return AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperNewProxyInstance, array);
		}
 public static void CheckException()
 {
   IntPtr localref = AndroidJNI.ExceptionOccurred();
   if (!(localref != IntPtr.Zero))
     return;
   AndroidJNI.ExceptionClear();
   IntPtr num1 = AndroidJNI.FindClass("java/lang/Throwable");
   IntPtr num2 = AndroidJNI.FindClass("android/util/Log");
   try
   {
     IntPtr methodId = AndroidJNI.GetMethodID(num1, "toString", "()Ljava/lang/String;");
     IntPtr staticMethodId = AndroidJNI.GetStaticMethodID(num2, "getStackTraceString", "(Ljava/lang/Throwable;)Ljava/lang/String;");
     string message = AndroidJNI.CallStringMethod(localref, methodId, new jvalue[0]);
     jvalue[] args = new jvalue[1];
     args[0].l = localref;
     string javaStackTrace = AndroidJNI.CallStaticStringMethod(num2, staticMethodId, args);
     throw new AndroidJavaException(message, javaStackTrace);
   }
   finally
   {
     AndroidJNISafe.DeleteLocalRef(localref);
     AndroidJNISafe.DeleteLocalRef(num1);
     AndroidJNISafe.DeleteLocalRef(num2);
   }
 }
	public static void Destroy() {
		
		#if UNITY_ANDROID && !UNITY_EDITOR
		JavaVM.AttachCurrentThread();
		jvalue[] args = new jvalue[] {};
		AndroidJNI.CallVoidMethod(LoopMeClass, DestroyPtr, args);
		#endif			
	}
示例#6
0
 public static void SetNativeExceptionOnProxy(IntPtr proxy, Exception e, bool methodNotFound)
 {
     jvalue[] array = new jvalue[3];
     array[0].l = proxy;
     array[1].j = GCHandle.ToIntPtr(GCHandle.Alloc(e)).ToInt64();
     array[2].z = methodNotFound;
     AndroidJNISafe.CallStaticVoidMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperSetNativeExceptionOnProxy, array);
 }
 private static void BurstlyAdWrapper_createBannerPlacement(string placementName, string appId, string zoneId, float originX, float originY, float width, float height)
 {
     jvalue[] args = new jvalue[7];
       		args[0].l = AndroidJNI.NewStringUTF(placementName);
       		args[1].l = AndroidJNI.NewStringUTF(appId);
       		args[2].l = AndroidJNI.NewStringUTF(zoneId);
         args[3].f = originX;
         args[4].f = originY;
         args[5].f = width;
         args[6].f = height;
         AndroidJNI.CallStaticVoidMethod(BurstlyPluginClass, methodID_createBannerPlacement, args);
 }
示例#8
0
    public static int Write(ref int[] data)
    {
        IntPtr pArr = AndroidJNIHelper.ConvertToJNIArray(data);
        jvalue[] blah = new jvalue[1];
        blah[0].l = pArr;

        if (writeMethodId == null)
            writeMethodId = AndroidJNIHelper.GetMethodID(jo.GetRawClass(), "writeUsbPort");
        int ret = AndroidJNI.CallIntMethod(jo.GetRawObject(), writeMethodId, blah);
        AndroidJNI.DeleteLocalRef(pArr);
        return ret;
    }
示例#9
0
 public static bool CallBooleanMethod(IntPtr obj, IntPtr methodID, jvalue[] args)
 {
     bool flag;
     try
     {
         flag = AndroidJNI.CallBooleanMethod(obj, methodID, args);
     }
     finally
     {
         CheckException();
     }
     return flag;
 }
示例#10
0
 public static int CallIntMethod(IntPtr obj, IntPtr methodID, jvalue[] args)
 {
     int num;
     try
     {
         num = AndroidJNI.CallIntMethod(obj, methodID, args);
     }
     finally
     {
         CheckException();
     }
     return num;
 }
示例#11
0
 public static double CallDoubleMethod(IntPtr obj, IntPtr methodID, jvalue[] args)
 {
     double num;
     try
     {
         num = AndroidJNI.CallDoubleMethod(obj, methodID, args);
     }
     finally
     {
         CheckException();
     }
     return num;
 }
示例#12
0
 public static char CallCharMethod(IntPtr obj, IntPtr methodID, jvalue[] args)
 {
     char ch;
     try
     {
         ch = AndroidJNI.CallCharMethod(obj, methodID, args);
     }
     finally
     {
         CheckException();
     }
     return ch;
 }
 public static IntPtr GetConstructorMember(IntPtr jclass, string signature)
 {
   jvalue[] args = new jvalue[2];
   try
   {
     args[0].l = jclass;
     args[1].l = AndroidJNISafe.NewStringUTF(signature);
     return AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetConstructorID, args);
   }
   finally
   {
     AndroidJNISafe.DeleteLocalRef(args[1].l);
   }
 }
 public static IntPtr GetConstructorMember(IntPtr jclass, string signature)
 {
     jvalue[] args = new jvalue[2];
     try
     {
         args[0].l = jclass;
         args[1].l = AndroidJNISafe.NewStringUTF(signature);
         return(AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetConstructorID, args));
     }
     finally
     {
         AndroidJNISafe.DeleteLocalRef(args[1].l);
     }
 }
        public void closeWebView()
        {
            // attach our thread to the java vm
                bool mainThread = (mainThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId);
                AndroidJNI.AttachCurrentThread();

                // call
                jvalue[] args =  new jvalue[0];

            AndroidJNI.CallStaticVoidMethod(JavaClass, CloseWebViewId,args);

                if(mainThread == false){
                    AndroidJNI.DetachCurrentThread();
                }
        }
 public static IntPtr GetFieldMember(IntPtr jclass, string fieldName, string signature, bool isStatic)
 {
   jvalue[] args = new jvalue[4];
   try
   {
     args[0].l = jclass;
     args[1].l = AndroidJNISafe.NewStringUTF(fieldName);
     args[2].l = AndroidJNISafe.NewStringUTF(signature);
     args[3].z = isStatic;
     return AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetFieldID, args);
   }
   finally
   {
     AndroidJNISafe.DeleteLocalRef(args[1].l);
     AndroidJNISafe.DeleteLocalRef(args[2].l);
   }
 }
 public static IntPtr GetFieldMember(IntPtr jclass, string fieldName, string signature, bool isStatic)
 {
     jvalue[] args = new jvalue[4];
     try
     {
         args[0].l = jclass;
         args[1].l = AndroidJNISafe.NewStringUTF(fieldName);
         args[2].l = AndroidJNISafe.NewStringUTF(signature);
         args[3].z = isStatic;
         return(AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetFieldID, args));
     }
     finally
     {
         AndroidJNISafe.DeleteLocalRef(args[1].l);
         AndroidJNISafe.DeleteLocalRef(args[2].l);
     }
 }
示例#18
0
 public static IntPtr GetMethodMember(IntPtr jclass, string methodName, string signature, bool isStatic)
 {
     jvalue[] array = new jvalue[4];
     try
     {
         array[0].l = jclass;
         array[1].l = AndroidJNISafe.NewStringUTF(methodName);
         array[2].l = AndroidJNISafe.NewStringUTF(signature);
         array[3].z = isStatic;
         return(AndroidJNISafe.CallStaticObjectMethod(s_ReflectionHelperClass, s_ReflectionHelperGetMethodID, array));
     }
     finally
     {
         AndroidJNISafe.DeleteLocalRef(array[1].l);
         AndroidJNISafe.DeleteLocalRef(array[2].l);
     }
 }
        public void openWebView(String url)
        {
            // attach our thread to the java vm; obviously the main thread is already attached but this is good practice..
                bool mainThread = (mainThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId);

                AndroidJNI.AttachCurrentThread();

                // call
                jvalue[] args =  new jvalue[1];
                args[0] = new jvalue();
                args[0].l = AndroidJNI.NewStringUTF(url);

                AndroidJNI.CallStaticVoidMethod(JavaClass, OpenWebViewId,args);

                if(mainThread == false){
                    AndroidJNI.DetachCurrentThread();
                }
        }
示例#20
0
    void OnGUI()
    {
        if (GUI.Button(new Rect(200, 10, 200, 100), "GetPWCheckValue4"))
        {
            string strCrc = jo.Call<string>("GetPWCheckValue4", (long)lineId, (long)machineId, (long)maxProfit, (long)profit, (long)checkCount);
            int value;
            if (int.TryParse(strCrc, out value))
            {
                crc = value;
            }
            DebugConsole.Log("校验码=" + crc.ToString());
        }

        if (GUI.Button(new Rect(200, 150, 200, 100), "CreateCheckPWString"))
        {
            AndroidJavaObject rev = jo.Call<AndroidJavaObject>("CreateCheckPWString",
                                                               (long)lineId, (long)machineId, (long)maxProfit, (long)profit, (long)checkCount, (long)crc, (long)userInput);
            byte[] buf = AndroidJNIHelper.ConvertFromJNIArray<byte[]>(rev.GetRawObject());
            string log = "c# CreateCheckPWString:";
            foreach (byte b in buf)
                log += string.Format("{0:X}", b) + ", ";
            DebugConsole.Log(log);
            List<int> data = new List<int>();
            data.Add(0x42);
            data.Add(0x5a);
            data.Add(32);
            foreach(byte b in buf)
                data.Add((int)b);
            while (data.Count < 64)
                data.Add(0);
            hidUtils.WriteData(data.ToArray());
        }

        if (GUI.Button(new Rect(200, 300, 200, 100), "GetCheckPWStringValue"))
        {
            byte[] data = sendToChip.ToArray();
            IntPtr pArr = AndroidJNIHelper.ConvertToJNIArray(data);
            jvalue[] blah = new jvalue[1];
            blah[0].l = pArr;

            IntPtr methodId = AndroidJNIHelper.GetMethodID(jo.GetRawClass(), "GetCheckPWStringValue");
            DebugConsole.Log(AndroidJNI.CallStringMethod(jo.GetRawObject(), methodId, blah));
        }
    }
		public static IntPtr GetMethodMember(IntPtr jclass, string methodName, string signature, bool isStatic)
		{
			jvalue[] array = new jvalue[4];
			IntPtr result;
			try
			{
				array[0].l = jclass;
				array[1].l = AndroidJNISafe.NewStringUTF(methodName);
				array[2].l = AndroidJNISafe.NewStringUTF(signature);
				array[3].z = isStatic;
				result = AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetMethodID, array);
			}
			finally
			{
				AndroidJNISafe.DeleteLocalRef(array[1].l);
				AndroidJNISafe.DeleteLocalRef(array[2].l);
			}
			return result;
		}
示例#22
0
 public static IntPtr GetMethodMember(IntPtr jclass, string methodName, string signature, bool isStatic)
 {
     IntPtr ptr;
     jvalue[] args = new jvalue[4];
     try
     {
         args[0].l = jclass;
         args[1].l = AndroidJNISafe.NewStringUTF(methodName);
         args[2].l = AndroidJNISafe.NewStringUTF(signature);
         args[3].z = isStatic;
         ptr = AndroidJNISafe.CallStaticObjectMethod(s_ReflectionHelperClass, s_ReflectionHelperGetMethodID, args);
     }
     finally
     {
         AndroidJNISafe.DeleteLocalRef(args[1].l);
         AndroidJNISafe.DeleteLocalRef(args[2].l);
     }
     return ptr;
 }
        public string getItem(string key)
        {
            // attach our thread to the java vm
                bool mainThread = (mainThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId);
                AndroidJNI.AttachCurrentThread();

                // call
                jvalue[] args =  new jvalue[1];
                args[0] = new jvalue();
                args[0].l = AndroidJNI.NewStringUTF(key);

                string result = AndroidJNI.CallStaticStringMethod(JavaClass, GetItemId,args);

                // detach our thread to the java vm
                if(mainThread == false){
                    AndroidJNI.DetachCurrentThread();
                }

                return result;
        }
示例#24
0
        public void getHttp( String url, NetConnectionReceivedHandler connectionReceivedHandler, NetConnectionSendFailHandler asyncSendFailResult)
        {
            _currentGetConnectionReceivedHandler = connectionReceivedHandler;
            _currentGetAsyncSendFailResult = asyncSendFailResult;

            // attach our thread to the java vm
            bool mainThread = (mainThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId);
            AndroidJNI.AttachCurrentThread();

            // call
            jvalue[] args =  new jvalue[1];
            args[0] = new jvalue();
            args[0].l = AndroidJNI.NewStringUTF(url);

            AndroidJNI.CallStaticVoidMethod(JavaClass, HttpGetId,args);

            if(mainThread == false){
                AndroidJNI.DetachCurrentThread();
            }
        }
		public override void RecordCustomException(string name, string reason, string stackTraceString)
		{
			// new Exception(message)
			var exceptionClass = AndroidJNI.FindClass("java/lang/Exception");
			var exceptionConstructor = AndroidJNI.GetMethodID (exceptionClass, "<init>", "(Ljava/lang/String;)V");
			var exceptionArgs = new jvalue[1];
			exceptionArgs[0].l = AndroidJNI.NewStringUTF(name + " : " + reason);
			var exceptionObj = AndroidJNI.NewObject (exceptionClass, exceptionConstructor, exceptionArgs);

			// stackTrace = [StackTraceElement, ...]
			var stackTraceElClass = AndroidJNI.FindClass ("java/lang/StackTraceElement");
			var stackTraceElConstructor = AndroidJNI.GetMethodID (stackTraceElClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V");
			var parsedStackTrace = ParseStackTraceString (stackTraceString);
			var stackTraceArray = AndroidJNI.NewObjectArray(parsedStackTrace.Length, stackTraceElClass, IntPtr.Zero);
			for (var i = 0; i < parsedStackTrace.Length; i++) {
			var frame = parsedStackTrace[i];

			// new StackTraceElement()
			var stackTraceArgs = new jvalue[4];
			stackTraceArgs[0].l = AndroidJNI.NewStringUTF(frame["class"]);
			stackTraceArgs[1].l = AndroidJNI.NewStringUTF(frame["method"]);
			stackTraceArgs[2].l = AndroidJNI.NewStringUTF(frame["file"]);
			stackTraceArgs[3].i = Int32.Parse(frame["line"]);
			var stackTraceEl = AndroidJNI.NewObject (stackTraceElClass, stackTraceElConstructor, stackTraceArgs);
			AndroidJNI.SetObjectArrayElement(stackTraceArray, i, stackTraceEl);
			}

			// exception.setStackTrace(stackTraceArray)
			var setStackTraceMethod = AndroidJNI.GetMethodID (exceptionClass, "setStackTrace", "([Ljava/lang/StackTraceElement;)V");
			var setStackTraceArgs = new jvalue[1];
			setStackTraceArgs[0].l = stackTraceArray;
			AndroidJNI.CallVoidMethod (exceptionObj, setStackTraceMethod, setStackTraceArgs);

			// Crashlytics.logException(exception)
			var crashClass = AndroidJNI.FindClass ("com/crashlytics/android/Crashlytics");
			var logExceptionMethod = AndroidJNI.GetStaticMethodID (crashClass, "logException", "(Ljava/lang/Throwable;)V");
			var logExceptionArgs = new jvalue[1];
			logExceptionArgs[0].l = exceptionObj;
			AndroidJNI.CallStaticVoidMethod (crashClass, logExceptionMethod, logExceptionArgs);
		}
    private string GetAndroidMusicDirectory()
    {
        // Use the AndroidJNI wrapper class to call native Android code.
        // Specifically we want to call Environment.getExternalStoragePublicDirectory()
        // with the string parameter Environment.DIRECTORY_MUSIC.
        // This method returns a Java File object which we can convert to the string
        // file path using its getPath() method.

        // Construct the various inputs needed to retrieve the Environment class
        // and call its getExternalStoragePublicDirectory() static method.
        string className = "android/os/Environment";
        string getFileObjMethodName = "getExternalStoragePublicDirectory";
        string musicDirTagFieldName = "DIRECTORY_MUSIC";
        string getFileObjMethodJNISig = "(" + JNI_STRING_SIG + ")" + JNI_FILE_SIG;

        // Get the class and method ID.
        IntPtr envClass = AndroidJNI.FindClass(className);
        IntPtr getFileObjMethodID =  AndroidJNI.GetStaticMethodID(envClass, getFileObjMethodName, getFileObjMethodJNISig);

        // Get the Environment.DIRECTORY_MUSIC tag string.
        IntPtr musicDirTagFieldID = AndroidJNI.GetStaticFieldID(envClass, musicDirTagFieldName, JNI_STRING_SIG);
        string musicDirTag = AndroidJNI.GetStaticStringField(envClass, musicDirTagFieldID);
        
        // Wrap the tag in a jvalue array as required for JNI arguments.
        jvalue[] args = new jvalue[1];
        args[0] = new jvalue();
        args[0].l = AndroidJNI.NewStringUTF(musicDirTag);

        // Call the getExternalStoragePublicDirectory() method to obtain the Java File object.
        IntPtr fileObject = AndroidJNI.CallStaticObjectMethod(envClass, getFileObjMethodID, args);
        
        // Convert the File to a string by calling its getPath() method.
        IntPtr fileClass = AndroidJNI.FindClass("java/io/File");
        string getPathMethodJNISig = "()" + JNI_STRING_SIG;
        IntPtr getPathMethodID = AndroidJNI.GetMethodID(fileClass, "getPath", getPathMethodJNISig);
        
        string musicDirectoryPath = AndroidJNI.CallStringMethod(fileObject, getPathMethodID, new jvalue[1]);
        return musicDirectoryPath;
    }
示例#27
0
 static int AndroidGetAvailableViews( string zone_id )
 {
   jvalue[] args = new jvalue[1];
   args[0].l = AndroidJNI.NewStringUTF( zone_id );
   return AndroidJNI.CallStaticIntMethod( class_UnityADC, method_getAvailableViews, args );
 }
示例#28
0
 static string AndroidStatusForZone( string zone_id )
 {
   jvalue[] args = new jvalue[1];
   args[0].l = AndroidJNI.NewStringUTF( zone_id );
   return AndroidJNI.CallStaticStringMethod( class_UnityADC, method_statusForZone, args );
 }
示例#29
0
 static void AndroidOfferV4VC( bool popup_result, string zone_id )
 {
   jvalue[] args = new jvalue[2];
   args[0].z = popup_result;
   args[1].l = AndroidJNI.NewStringUTF( zone_id );
   AndroidJNI.CallStaticVoidMethod( class_UnityADC, method_offerV4VC, args );
 }
示例#30
0
 static bool AndroidShowV4VC( bool popup_result, string zone_id )
 {
   jvalue[] args = new jvalue[2];
   args[0].z = popup_result;
   args[1].l = AndroidJNI.NewStringUTF( zone_id );
   AndroidJNI.CallStaticBooleanMethod( class_UnityADC, method_showV4VC, args );
   return true;
 }
示例#31
0
 static bool AndroidShowVideoAd( string zone_id )
 {
   jvalue[] args = new jvalue[1];
   args[0].l = AndroidJNI.NewStringUTF( zone_id );
   AndroidJNI.CallStaticBooleanMethod( class_UnityADC, method_showVideo, args );
   return true;
 }
示例#32
0
 static string AndroidGetDeviceID()
 {
   jvalue[] args = new jvalue[0];
   return AndroidJNI.CallStaticStringMethod( class_UnityADC, method_getDeviceID, args );
 }
示例#33
0
 static bool AndroidIsV4VCAvailable( string zone_id )
 {
   jvalue[] args = new jvalue[1];
   args[0].l = AndroidJNI.NewStringUTF( zone_id );
   return AndroidJNI.CallStaticBooleanMethod( class_UnityADC, method_isV4VCAvailable, args );
 }
示例#34
0
 static void AndroidSetCustomID( string custom_id )
 {
   if(!adr_initialized) AndroidInitializePlugin();
   jvalue[] args = new jvalue[1];
   args[0].l = AndroidJNI.NewStringUTF( custom_id );
   AndroidJNI.CallStaticVoidMethod( class_UnityADC, method_setCustomID, args );
 }
示例#35
0
 public static string GetFieldSignature(IntPtr field)
 {
     jvalue[] array = new jvalue[1];
     array[0].l = field;
     return(AndroidJNISafe.CallStaticStringMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetFieldSignature, array));
 }
 public virtual int hashCode()
 {
     jvalue[] array = new jvalue[1];
     array[0].l = this.GetProxy().GetRawObject();
     return(AndroidJNISafe.CallStaticIntMethod(AndroidJavaProxy.s_JavaLangSystemClass, AndroidJavaProxy.s_HashCodeMethodID, array));
 }
示例#37
0
        public static jvalue[] CreateJNIArgArray(object[] args)
        {
            jvalue[] array = new jvalue[args.GetLength(0)];
            int      num   = 0;

            foreach (object obj in args)
            {
                if (obj == null)
                {
                    array[num].l = IntPtr.Zero;
                }
                else if (AndroidReflection.IsPrimitive(obj.GetType()))
                {
                    if (obj is int)
                    {
                        array[num].i = (int)obj;
                    }
                    else if (obj is bool)
                    {
                        array[num].z = (bool)obj;
                    }
                    else if (obj is byte)
                    {
                        array[num].b = (byte)obj;
                    }
                    else if (obj is short)
                    {
                        array[num].s = (short)obj;
                    }
                    else if (obj is long)
                    {
                        array[num].j = (long)obj;
                    }
                    else if (obj is float)
                    {
                        array[num].f = (float)obj;
                    }
                    else if (obj is double)
                    {
                        array[num].d = (double)obj;
                    }
                    else if (obj is char)
                    {
                        array[num].c = (char)obj;
                    }
                }
                else if (obj is string)
                {
                    array[num].l = AndroidJNISafe.NewStringUTF((string)obj);
                }
                else if (obj is AndroidJavaClass)
                {
                    array[num].l = ((AndroidJavaClass)obj).GetRawClass();
                }
                else if (obj is AndroidJavaObject)
                {
                    array[num].l = ((AndroidJavaObject)obj).GetRawObject();
                }
                else if (obj is Array)
                {
                    array[num].l = ConvertToJNIArray((Array)obj);
                }
                else if (obj is AndroidJavaProxy)
                {
                    array[num].l = AndroidJNIHelper.CreateJavaProxy((AndroidJavaProxy)obj);
                }
                else
                {
                    if (!(obj is AndroidJavaRunnable))
                    {
                        throw new Exception("JNI; Unknown argument type '" + obj.GetType() + "'");
                    }
                    array[num].l = AndroidJNIHelper.CreateJavaRunnable((AndroidJavaRunnable)obj);
                }
                num++;
            }
            return(array);
        }