public int read(ref byte[] bytes)
        {
            JNIFind();

            if (_instance == IntPtr.Zero)
            {
                Debug.LogError("_instance is not initialized");
                return(-1);
            }
            if (_jmRead == IntPtr.Zero)
            {
                Debug.LogError("_jmRead is not initialized");
                return(-1);
            }
            IntPtr arg1   = AndroidJNI.ToByteArray(bytes);
            int    result = AndroidJNI.CallIntMethod(_instance, _jmRead, new jvalue[] { new jvalue()
                                                                                        {
                                                                                            l = arg1
                                                                                        } });

            byte[] copy = AndroidJNI.FromByteArray(arg1);
            Array.Copy(copy, bytes, copy.Length);
            AndroidJNI.DeleteLocalRef(arg1);

            return(result);
        }
Beispiel #2
0
        static BitmapFactory()
        {
            try
            {
                {
                    string strName  = "android/graphics/BitmapFactory";
                    IntPtr localRef = AndroidJNI.FindClass(strName);
                    if (localRef != IntPtr.Zero)
                    {
#if VERBOSE_LOGGING
                        Debug.Log(string.Format("Found {0} class", strName));
#endif
                        _jcBitmapFactory = AndroidJNI.NewGlobalRef(localRef);
                        AndroidJNI.DeleteLocalRef(localRef);
                    }
                    else
                    {
                        Debug.LogError(string.Format("Failed to find {0} class", strName));
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError(string.Format("Exception loading JNI - {0}", ex));
            }
        }
        static InputStream()
        {
            try
            {
                {
                    string strName  = "java/io/InputStream";
                    IntPtr localRef = AndroidJNI.FindClass(strName);
                    if (localRef != IntPtr.Zero)
                    {
#if VERBOSE_LOGGING
                        Debug.Log(string.Format("Found {0} class", strName));
#endif
                        _jcInputStream = AndroidJNI.NewGlobalRef(localRef);
                        AndroidJNI.DeleteLocalRef(localRef);
                    }
                    else
                    {
                        Debug.LogError(string.Format("Failed to find {0} class", strName));
                        return;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError(string.Format("Exception loading JNI - {0}", ex));
            }
        }
        public static void getOuyaContentPublished(OuyaContent.SortMethod sortMethod)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return;
            }
            if (_jmGetOuyaContentPublished == IntPtr.Zero)
            {
                Debug.LogError("_jmGetOuyaContentPublished is not initialized");
                return;
            }

            String strSortMethod = sortMethod.ToString();
            //Debug.Log(string.Format("SortMethod={0}", strSortMethod));
            IntPtr arg1 = AndroidJNI.NewStringUTF(strSortMethod);
            AndroidJNI.CallStaticVoidMethod(_jcOuyaUnityPlugin, _jmGetOuyaContentPublished, new jvalue[] { new jvalue()
                                                                                                           {
                                                                                                               l = arg1
                                                                                                           } });
            AndroidJNI.DeleteLocalRef(arg1);
        }
    //We need this because normal Unity calls to native methods crash if the native method returns null.
    public static string SafeCallStringMethod(AndroidJavaObject javaObject, string methodName, params object[] args)
    {
#if UNITY_2018_2_OR_NEWER
        if (args == null)
        {
            args = new object[] { null }
        }
        ;
        IntPtr   methodID = AndroidJNIHelper.GetMethodID <string>(javaObject.GetRawClass(), methodName, args, false);
        jvalue[] jniArgs  = AndroidJNIHelper.CreateJNIArgArray(args);

        try
        {
            IntPtr returnValue = AndroidJNI.CallObjectMethod(javaObject.GetRawObject(), methodID, jniArgs);
            if (IntPtr.Zero != returnValue)
            {
                var val = AndroidJNI.GetStringUTFChars(returnValue);
                AndroidJNI.DeleteLocalRef(returnValue);
                return(val);
            }
        }
        finally
        {
            AndroidJNIHelper.DeleteJNIArgArray(args, jniArgs);
        }

        return(null);
#else
        return(javaObject.Call <string>(methodName, args));
#endif
    }
        public static void requestPurchase(string identifier)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return;
            }
            if (_jmRequestPurchase == IntPtr.Zero)
            {
                Debug.LogError("_jmRequestPurchase is not initialized");
                return;
            }

            // Make one request at a time
            if (m_pendingRequestPurchase)
            {
                return;
            }
            m_pendingRequestPurchase = true;

            IntPtr arg1 = AndroidJNI.NewStringUTF(identifier);
            AndroidJNI.CallStaticVoidMethod(_jcOuyaUnityPlugin, _jmRequestPurchase, new jvalue[] { new jvalue()
                                                                                                   {
                                                                                                       l = arg1
                                                                                                   } });
            AndroidJNI.DeleteLocalRef(arg1);
        }
        public static OuyaContent getOuyaContent()
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return(null);
            }
            if (_jmGetOuyaContent == IntPtr.Zero)
            {
                Debug.LogError("_jmGetOuyaContent is not initialized");
                return(null);
            }
            IntPtr retVal = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetOuyaContent, new jvalue[0] {
            });
            if (retVal == IntPtr.Zero)
            {
                Debug.LogError("GetOuyaContent returned null");
                return(null);
            }
            IntPtr globalPtr = AndroidJNI.NewGlobalRef(retVal);
            AndroidJNI.DeleteLocalRef(retVal);
            return(new OuyaContent(globalPtr));
        }
        static OuyaUnityPlugin()
        {
            try
            {
                {
                    string strName  = "tv/ouya/sdk/OuyaUnityPlugin";
                    IntPtr localRef = AndroidJNI.FindClass(strName);
                    if (localRef != IntPtr.Zero)
                    {
#if VERBOSE_LOGGING
                        Debug.Log(string.Format("Found {0} class", strName));
#endif
                        _jcOuyaUnityPlugin = AndroidJNI.NewGlobalRef(localRef);
                        AndroidJNI.DeleteLocalRef(localRef);
                    }
                    else
                    {
                        Debug.LogError(string.Format("Failed to find {0} class", strName));
                        return;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError(string.Format("Exception loading JNI - {0}", ex));
            }
        }
        public static void requestProducts(string jsonData)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return;
            }
            if (_jmRequestProducts == IntPtr.Zero)
            {
                Debug.LogError("_jmGetProductsAsync is not initialized");
                return;
            }

            // Make one request at a time
            if (m_pendingRequestProducts)
            {
                return;
            }
            m_pendingRequestProducts = true;

            IntPtr arg1   = AndroidJNI.NewStringUTF(jsonData);
            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmRequestProducts, new jvalue[] { new jvalue()
                                                                                                                     {
                                                                                                                         l = arg1
                                                                                                                     } });
            AndroidJNI.DeleteLocalRef(arg1);
        }
        public static void putGameData(string key, string val)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return;
            }
            if (_jmPutGameData == IntPtr.Zero)
            {
                Debug.LogError("_jmPutGameData is not initialized");
                return;
            }
            IntPtr arg1 = AndroidJNI.NewStringUTF(key);
            IntPtr arg2 = AndroidJNI.NewStringUTF(val);
            AndroidJNI.CallStaticVoidMethod(_jcOuyaUnityPlugin, _jmPutGameData, new jvalue[] { new jvalue()
                                                                                               {
                                                                                                   l = arg1
                                                                                               }, new jvalue()
                                                                                               {
                                                                                                   l = arg2
                                                                                               } });
            AndroidJNI.DeleteLocalRef(arg1);
            AndroidJNI.DeleteLocalRef(arg2);
        }
        public static string getGameData(string key)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return(null);
            }
            if (_jmGetGameData == IntPtr.Zero)
            {
                Debug.LogError("_jmGetGameData is not initialized");
                return(null);
            }
            IntPtr arg1   = AndroidJNI.NewStringUTF(key);
            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetGameData, new jvalue[] { new jvalue()
                                                                                                                 {
                                                                                                                     l = arg1
                                                                                                                 } });
            AndroidJNI.DeleteLocalRef(arg1);

            if (result == IntPtr.Zero)
            {
                Debug.LogError("Failed to getGameData");
                return(null);
            }

            String retVal = AndroidJNI.GetStringUTFChars(result);
            return(retVal);
        }
        public static List <Bitmap> getBitmapList(IntPtr list)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return(null);
            }
            if (_jmGetBitmapArray == IntPtr.Zero)
            {
                Debug.LogError("_jmGetBitmapArray is not initialized");
                return(null);
            }

            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetBitmapArray, new jvalue[] { new jvalue()
                                                                                                                    {
                                                                                                                        l = list
                                                                                                                    } });
            if (result == IntPtr.Zero)
            {
                Debug.LogError("_jmGetBitmapArray returned null");
                return(null);
            }

            List <Bitmap> items = new List <Bitmap>();

#if VERBOSE_LOGGING
            Debug.Log("Invoking AndroidJNI.FromObjectArray...");
#endif
            IntPtr[] resultArray = AndroidJNI.FromObjectArray(result);
#if VERBOSE_LOGGING
            Debug.Log("Invoked AndroidJNI.FromObjectArray.");
#endif

            foreach (IntPtr ptr in resultArray)
            {
#if VERBOSE_LOGGING
                Debug.Log("Found Bitmap making Global Ref...");
#endif
                IntPtr globalRef = AndroidJNI.NewGlobalRef(ptr);
                AndroidJNI.DeleteLocalRef(ptr);
#if VERBOSE_LOGGING
                Debug.Log("Made global ref for Bitmap.");
#endif
                Bitmap item = new Bitmap(globalRef);
#if VERBOSE_LOGGING
                Debug.Log("Deleting old bitmap reference...");
#endif
                items.Add(item);
            }
#if VERBOSE_LOGGING
            Debug.Log("Deleting bitmap list reference...");
#endif
            AndroidJNI.DeleteLocalRef(result);
            return(items);
        }
        public static string getGameData(string key)
        {
            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return(null);
            }
            if (_jmGetGameData == IntPtr.Zero)
            {
                Debug.LogError("_jmGetGameData is not initialized");
                return(null);
            }
            IntPtr arg1   = AndroidJNI.NewStringUTF(key);
            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetGameData, new jvalue[] { new jvalue()
                                                                                                                 {
                                                                                                                     l = arg1
                                                                                                                 } });

            AndroidJNI.DeleteLocalRef(arg1);

            if (result == IntPtr.Zero)
            {
                Debug.LogError("Failed to getGameData");
                return(null);
            }

            String retVal = AndroidJNI.GetStringUTFChars(result);

            return(retVal);
        }
        public static void putGameData(string key, string val)
        {
            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return;
            }
            if (_jmPutGameData == IntPtr.Zero)
            {
                Debug.LogError("_jmPutGameData is not initialized");
                return;
            }
            IntPtr arg1 = AndroidJNI.NewStringUTF(key);
            IntPtr arg2 = AndroidJNI.NewStringUTF(val);

            AndroidJNI.CallStaticVoidMethod(_jcOuyaUnityPlugin, _jmPutGameData, new jvalue[] { new jvalue()
                                                                                               {
                                                                                                   l = arg1
                                                                                               }, new jvalue()
                                                                                               {
                                                                                                   l = arg2
                                                                                               } });
            AndroidJNI.DeleteLocalRef(arg1);
            AndroidJNI.DeleteLocalRef(arg2);
        }
Beispiel #15
0
            public override int Read(byte[] buffer, int offset, int count)
            {
                lock (_lock)
                {
                    int    ret   = 0;
                    IntPtr array = IntPtr.Zero;
                    try
                    {
#if UNITY_2019_3_OR_NEWER
                        array = AndroidJNI.NewSByteArray(count);
#else
                        array = AndroidJNI.NewByteArray(count);
#endif
                        var method = AndroidJNIHelper.GetMethodID(inputStream.GetRawClass(), "read", "([B)I");
                        ret = AndroidJNI.CallIntMethod(inputStream.GetRawObject(), method, new[] { new jvalue()
                                                                                                   {
                                                                                                       l = array
                                                                                                   } });
#if UNITY_2019_3_OR_NEWER
                        sbyte[] data = AndroidJNI.FromSByteArray(array);
#else
                        byte[] data = AndroidJNI.FromByteArray(array);
#endif
                        Array.Copy(data, 0, buffer, offset, ret);
                    }
                    finally
                    {
                        if (array != IntPtr.Zero)
                        {
                            AndroidJNI.DeleteLocalRef(array);
                        }
                    }
                    return(ret);
                }
            }
Beispiel #16
0
        public string getDeviceName()
        {
            if (_instance == IntPtr.Zero)
            {
                Debug.LogError("_instance is not initialized");
                return(null);
            }
            if (_jmGetDeviceName == IntPtr.Zero)
            {
                Debug.LogError("_jmGetDeviceName is not initialized");
                return(null);
            }
            IntPtr result = AndroidJNI.CallObjectMethod(_instance, _jmGetDeviceName, new jvalue[0]);

            if (result == IntPtr.Zero)
            {
                //might not be connected
                //Debug.LogError("Failed to get device name");
                return(null);
            }
            String retVal = AndroidJNI.GetStringUTFChars(result);

            AndroidJNI.DeleteLocalRef(result);
            return(retVal);
        }
        static AndroidFileSystemStream()
        {
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

            if (unityPlayer == null)
            {
                throw new GameFrameworkException("Unity player is invalid.");
            }

            AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");

            if (currentActivity == null)
            {
                throw new GameFrameworkException("Current activity is invalid.");
            }

            AndroidJavaObject assetManager = currentActivity.Call <AndroidJavaObject>("getAssets");

            if (assetManager == null)
            {
                throw new GameFrameworkException("Asset manager is invalid.");
            }

            s_AssetManager = assetManager;

            IntPtr inputStreamClassPtr = AndroidJNI.FindClass("java/io/InputStream");

            s_InternalReadMethodId = AndroidJNIHelper.GetMethodID(inputStreamClassPtr, "read", "([BII)I");
            s_InternalReadArgs     = new jvalue[3];

            AndroidJNI.DeleteLocalRef(inputStreamClassPtr);
            currentActivity.Dispose();
            unityPlayer.Dispose();
        }
        private int InternalRead(int length, out byte[] result)
        {
            IntPtr resultPtr = AndroidJNI.NewByteArray(length);
            int    offset    = 0;
            int    bytesLeft = length;

            while (bytesLeft > 0)
            {
                s_InternalReadArgs[0] = new jvalue()
                {
                    l = resultPtr
                };
                s_InternalReadArgs[1] = new jvalue()
                {
                    i = offset
                };
                s_InternalReadArgs[2] = new jvalue()
                {
                    i = bytesLeft
                };
                int bytesRead = AndroidJNI.CallIntMethod(m_FileStreamRawObject, s_InternalReadMethodId, s_InternalReadArgs);
                if (bytesRead <= 0)
                {
                    break;
                }

                offset    += bytesRead;
                bytesLeft -= bytesRead;
            }

            result = AndroidJNI.FromByteArray(resultPtr);
            AndroidJNI.DeleteLocalRef(resultPtr);
            return(offset);
        }
        public static void URLClientSetRequestContent(uint connectionID,
                                                      byte[] src, ulong srcLength)
        {
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_IPHONE
            GCHandle pinnedArray = GCHandle.Alloc(src, GCHandleType.Pinned);
            IntPtr   ptrSrc      = pinnedArray.AddrOfPinnedObject();
            _URLClientSetRequestContent(connectionID, ptrSrc, srcLength);
            pinnedArray.Free();
#elif UNITY_ANDROID
            IntPtr rawClass  = UnityURLClientBindingInstance.GetRawClass();
            IntPtr rawObject = UnityURLClientBindingInstance.GetRawObject();

            IntPtr methodPtr = AndroidJNI.GetMethodID(rawClass, "setRequestContent", "(I[BJ)V");

            IntPtr v2 = AndroidJNI.ToByteArray(src);
            jvalue j1 = new jvalue();
            j1.i = (int)connectionID;
            jvalue j2 = new jvalue();
            j2.l = v2;
            jvalue j3 = new jvalue();
            j3.j = (long)srcLength;

            AndroidJNI.CallVoidMethod(rawObject, methodPtr, new jvalue[] { j1, j2, j3 });
            AndroidJNI.DeleteLocalRef(v2);
#endif
        }
Beispiel #20
0
            public override int Read(byte[] buffer, int offset, int count)
            {
                lock (_lock)
                {
                    int    ret   = 0;
                    IntPtr array = IntPtr.Zero;
                    try
                    {
                        array = AndroidJNI.NewByteArray(count);
                        var method = AndroidJNIHelper.GetMethodID(inputStream.GetRawClass(), "read", "([B)I");
                        ret = AndroidJNI.CallIntMethod(inputStream.GetRawObject(), method, new[] { new jvalue()
                                                                                                   {
                                                                                                       l = array
                                                                                                   } });
                        if (ret <= 0)
                        {
                            return(ret);
                        }

                        byte[] data = AndroidJNI.FromByteArray(array);
                        //Array.Copy(data, 0, buffer, offset, ret);
                        Buffer.BlockCopy(data, 0, buffer, 0, ret);
                        this.position += ret;
                    }
                    finally
                    {
                        if (array != IntPtr.Zero)
                        {
                            AndroidJNI.DeleteLocalRef(array);
                        }
                    }
                    return(ret);
                }
            }
Beispiel #21
0
 public void Dispose()
 {
     if (_instance != IntPtr.Zero)
     {
         AndroidJNI.DeleteLocalRef(_instance);
         _instance = IntPtr.Zero;
     }
 }
        public static void DeleteLocalRef(IntPtr localRef)
        {
            if (!(localRef != IntPtr.Zero))
            {
                return;
            }

            AndroidJNI.DeleteLocalRef(localRef);
        }
        internal AndroidNativeControllerProvider()
        {
#if !UNITY_EDITOR
            Debug.Log("Initializing Daydream controller API.");

            int options = gvr_controller_get_default_options();
            options |= GVR_CONTROLLER_ENABLE_ACCEL;
            options |= GVR_CONTROLLER_ENABLE_GYRO;

            statePtr = gvr_controller_state_create();
            // Get a hold of the activity, context and class loader.
            AndroidJavaObject activity = GvrActivityHelper.GetActivity();
            if (activity == null)
            {
                error        = true;
                errorDetails = "Failed to get Activity from Unity Player.";
                return;
            }
            androidContext = GvrActivityHelper.GetApplicationContext(activity);
            if (androidContext == null)
            {
                error        = true;
                errorDetails = "Failed to get Android application context from Activity.";
                return;
            }
            classLoader = GetClassLoaderFromActivity(activity);
            if (classLoader == null)
            {
                error        = true;
                errorDetails = "Failed to get class loader from Activity.";
                return;
            }

            // Use IntPtr instead of GetRawObject() so that Unity can shut down gracefully on
            // Application.Quit(). Note that GetRawObject() is not pinned by the receiver so it's not
            // cleaned up appropriately on shutdown, which is a known bug in Unity.
            IntPtr androidContextPtr = AndroidJNI.NewLocalRef(androidContext.GetRawObject());
            IntPtr classLoaderPtr    = AndroidJNI.NewLocalRef(classLoader.GetRawObject());
            Debug.Log("Creating and initializing GVR API controller object.");
            api = gvr_controller_create_and_init_android(IntPtr.Zero, androidContextPtr, classLoaderPtr,
                                                         options, IntPtr.Zero);
            AndroidJNI.DeleteLocalRef(androidContextPtr);
            AndroidJNI.DeleteLocalRef(classLoaderPtr);
            if (IntPtr.Zero == api)
            {
                Debug.LogError("Error creating/initializing Daydream controller API.");
                error        = true;
                errorDetails = "Failed to initialize Daydream controller API.";
                return;
            }

            Debug.Log("GVR API successfully initialized. Now resuming it.");
            gvr_controller_resume(api);
            Debug.Log("GVR API resumed.");
#endif
        }
Beispiel #24
0
    static void AndroidInitializePlugin()
    {
        bool   success = true;
        IntPtr local_class_UnityADC = AndroidJNI.FindClass("com/jirbo/unityadc/UnityADC");

        if (local_class_UnityADC != IntPtr.Zero)
        {
            class_UnityADC = AndroidJNI.NewGlobalRef(local_class_UnityADC);
            AndroidJNI.DeleteLocalRef(local_class_UnityADC);
            var local_class_AdColony = AndroidJNI.FindClass("com/jirbo/adcolony/AdColony");
            if (local_class_AdColony != IntPtr.Zero)
            {
                AndroidJNI.DeleteLocalRef(local_class_AdColony);
            }
            else
            {
                success = false;
            }
        }
        else
        {
            success = false;
        }

        if (success)
        {
            class_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            // Get additional method IDs for later use.
            method_configure = AndroidJNI.GetStaticMethodID(class_UnityADC, "configure",
                                                            "(Landroid/app/Activity;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V");

            method_pause             = AndroidJNI.GetStaticMethodID(class_UnityADC, "pause", "(Landroid/app/Activity;)V");
            method_resume            = AndroidJNI.GetStaticMethodID(class_UnityADC, "resume", "(Landroid/app/Activity;)V");
            method_setCustomID       = AndroidJNI.GetStaticMethodID(class_UnityADC, "setCustomID", "(Ljava/lang/String;)V");
            method_getCustomID       = AndroidJNI.GetStaticMethodID(class_UnityADC, "getCustomID", "()Ljava/lang/String;");
            method_isVideoAvailable  = AndroidJNI.GetStaticMethodID(class_UnityADC, "isVideoAvailable", "(Ljava/lang/String;)Z");
            method_isV4VCAvailable   = AndroidJNI.GetStaticMethodID(class_UnityADC, "isV4VCAvailable", "(Ljava/lang/String;)Z");
            method_getDeviceID       = AndroidJNI.GetStaticMethodID(class_UnityADC, "getDeviceID", "()Ljava/lang/String;");
            method_getV4VCAmount     = AndroidJNI.GetStaticMethodID(class_UnityADC, "getV4VCAmount", "(Ljava/lang/String;)I");
            method_getV4VCName       = AndroidJNI.GetStaticMethodID(class_UnityADC, "getV4VCName", "(Ljava/lang/String;)Ljava/lang/String;");
            method_showVideo         = AndroidJNI.GetStaticMethodID(class_UnityADC, "showVideo", "(Ljava/lang/String;)Z");
            method_showV4VC          = AndroidJNI.GetStaticMethodID(class_UnityADC, "showV4VC", "(ZLjava/lang/String;)Z");
            method_offerV4VC         = AndroidJNI.GetStaticMethodID(class_UnityADC, "offerV4VC", "(ZLjava/lang/String;)V");
            method_statusForZone     = AndroidJNI.GetStaticMethodID(class_UnityADC, "statusForZone", "(Ljava/lang/String;)Ljava/lang/String;");
            method_getAvailableViews = AndroidJNI.GetStaticMethodID(class_UnityADC, "getAvailableViews", "(Ljava/lang/String;)I");
            method_notifyIAPComplete = AndroidJNI.GetStaticMethodID(class_UnityADC, "notifyIAPComplete", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;D)V");

            adr_initialized = true;
        }
        else
        {
            // adcolony.jar and unityadc.jar most both be in Assets/Plugins/Android/ !
            Debug.LogError("AdColony configuration error - make sure adcolony.jar and "
                           + "unityadc.jar libraries are in your Unity project's Assets/Plugins/Android folder.");
        }
    }
Beispiel #25
0
        public void Dispose()
        {
#if VERBOSE_LOGGING
            Debug.Log(MethodBase.GetCurrentMethod().Name);
#endif
            if (_instance != IntPtr.Zero)
            {
                AndroidJNI.DeleteLocalRef(_instance);
                _instance = IntPtr.Zero;
            }
        }
Beispiel #26
0
    private void                    _OpenForPublish(string[] permissions, int handle)
    {
        object[] args = new object[2] {
            handle,
            new AndroidJavaObject(AndroidJNIHelper.ConvertToJNIArray(permissions))
        };
        IntPtr method_ptr = AndroidJNI.GetMethodID(android.GetRawClass(),
                                                   "OpenForPublish", Method_intStringArraySigniture);

        AndroidJNI.CallVoidMethod(android.GetRawObject(), method_ptr, AndroidJNIHelper.CreateJNIArgArray(args));
        AndroidJNI.DeleteLocalRef(method_ptr);
    }
Beispiel #27
0
        public override void RecordCustomException(string name, string reason, string stackTraceString)
        {
            this.references.Clear();
            IntPtr num1      = AndroidJNI.FindClass("java/lang/Exception");
            IntPtr methodId1 = AndroidJNI.GetMethodID(num1, "<init>", "(Ljava/lang/String;)V");

            jvalue[] jvalueArray1 = new jvalue[1];
            jvalueArray1[0].l = (__Null)AndroidJNI.NewStringUTF(name + " : " + reason);
            IntPtr num2 = AndroidJNI.NewObject(num1, methodId1, jvalueArray1);

            this.references.Add((IntPtr)jvalueArray1[0].l);
            this.references.Add(num2);
            IntPtr num3      = AndroidJNI.FindClass("java/lang/StackTraceElement");
            IntPtr methodId2 = AndroidJNI.GetMethodID(num3, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V");

            Dictionary <string, string>[] stackTraceString1 = Impl.ParseStackTraceString(stackTraceString);
            IntPtr num4 = AndroidJNI.NewObjectArray(stackTraceString1.Length, num3, IntPtr.Zero);

            this.references.Add(num4);
            for (int index = 0; index < stackTraceString1.Length; ++index)
            {
                Dictionary <string, string> dictionary = stackTraceString1[index];
                jvalue[] jvalueArray2 = new jvalue[4];
                jvalueArray2[0].l = (__Null)AndroidJNI.NewStringUTF(dictionary["class"]);
                jvalueArray2[1].l = (__Null)AndroidJNI.NewStringUTF(dictionary["method"]);
                jvalueArray2[2].l = (__Null)AndroidJNI.NewStringUTF(dictionary["file"]);
                this.references.Add((IntPtr)jvalueArray2[0].l);
                this.references.Add((IntPtr)jvalueArray2[1].l);
                this.references.Add((IntPtr)jvalueArray2[2].l);
                jvalueArray2[3].i = (__Null)int.Parse(dictionary["line"]);
                IntPtr num5 = AndroidJNI.NewObject(num3, methodId2, jvalueArray2);
                this.references.Add(num5);
                AndroidJNI.SetObjectArrayElement(num4, index, num5);
            }
            IntPtr methodId3 = AndroidJNI.GetMethodID(num1, "setStackTrace", "([Ljava/lang/StackTraceElement;)V");

            jvalue[] jvalueArray3 = new jvalue[1];
            jvalueArray3[0].l = (__Null)num4;
            AndroidJNI.CallVoidMethod(num2, methodId3, jvalueArray3);
            IntPtr num6           = AndroidJNI.FindClass("com/crashlytics/android/Crashlytics");
            IntPtr staticMethodId = AndroidJNI.GetStaticMethodID(num6, "logException", "(Ljava/lang/Throwable;)V");

            jvalue[] jvalueArray4 = new jvalue[1];
            jvalueArray4[0].l = (__Null)num2;
            AndroidJNI.CallStaticVoidMethod(num6, staticMethodId, jvalueArray4);
            using (List <IntPtr> .Enumerator enumerator = this.references.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    AndroidJNI.DeleteLocalRef(enumerator.Current);
                }
            }
        }
        public static byte[] ConvertByteArray(AndroidJavaObject byteArrayObj)
        {
            Debug.Log("ConvertByteArray.");

            if (byteArrayObj == null)
            {
                return(null);
            }

            byte[] ret = AndroidJNI.FromByteArray(byteArrayObj.GetRawObject());
            AndroidJNI.DeleteLocalRef(byteArrayObj.GetRawObject());
            return(ret);
        }
Beispiel #29
0
 public void OnActionRegistered(CRegistry registry, CAction action)
 {
     try
     {
         m_args2[0] = jval(action.Id);
         m_args2[1] = jval(action.Name);
         CallStaticVoidMethod(m_methodRegisterAction, m_args2);
         AndroidJNI.DeleteLocalRef(m_args2[1].l);
     }
     catch (Exception e)
     {
         Debug.LogError("Exception while calling 'LunarConsole.OnActionRegistered': " + e.Message);
     }
 }
Beispiel #30
0
            public void OnLogMessageReceived(string message, string stackTrace, LogType type)
            {
                lock (m_logLock)
                {
                    m_args3[0] = jval(message);
                    m_args3[1] = jval(stackTrace);
                    m_args3[2] = jval((int)type);

                    CallStaticVoidMethod(m_methodLogMessage, m_args3);

                    AndroidJNI.DeleteLocalRef(m_args3[0].l);
                    AndroidJNI.DeleteLocalRef(m_args3[1].l);
                }
            }