/// <summary>
    /// 检查函数是否存在
    /// </summary>
    /// <param name="methodName">函数名</param>
    /// <param name="returnType">返回类型的Type</param>
    /// <param name="isStatic">是否是静态函数</param>
    /// <param name="args">所有参数</param>
    /// <returns></returns>
    private bool CheckHaveFunInAndroid(string methodName, string returnType, bool isStatic, params object[] args)
    {
        string sigStr = GetSigStr(returnType, args);

        if (string.IsNullOrEmpty(sigStr))
        {
            Debug.Log("the Android Method args is wrong");
            return(false);
        }
        IntPtr fid;

        //通过方法名称和参数,获取方法的id,如果方法不存在,fid 为 new IntPtr(0)
        if (isStatic)
        {
            fid = AndroidJNI.GetStaticMethodID(baseJavaObject.GetRawClass(), methodName, sigStr);
        }
        else
        {
            fid = AndroidJNI.GetMethodID(baseJavaObject.GetRawClass(), methodName, sigStr);
        }

        if (fid != new IntPtr(0))
        {
            return(true);
        }
        else
        {
            AndroidJNI.ExceptionClear();
            return(false);
        }
    }
Exemple #2
0
        void ITalkingDataSDK.OnEvent(string eventId, Dictionary <string, object> eventData)
        {
            if (string.IsNullOrEmpty(eventId))
            {
                return;
            }

            if (eventData != null && eventData.Count > 0)
            {
                AndroidJavaObject map        = new AndroidJavaObject("java.util.HashMap", eventData.Count);
                IntPtr            method_put = AndroidJNIHelper.GetMethodID(map.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
                object[]          args       = new object[2];
                foreach (var kv in eventData)
                {
                    args[0] = new AndroidJavaObject("java.lang.String", kv.Key);
                    if (typeof(String).IsInstanceOfType(kv.Value))
                    {
                        args[1] = new AndroidJavaObject("java.lang.String", kv.Value);
                    }
                    else
                    {
                        args[1] = new AndroidJavaObject("java.lang.Double", "" + kv.Value);
                    }

                    AndroidJNI.CallObjectMethod(map.GetRawClass(), method_put, AndroidJNIHelper.CreateJNIArgArray(args));
                }
                CallMethod(mTalkingData, "onEvent", eventId, map);
            }
            else
            {
                CallMethod(mTalkingData, "onEvent", eventId, null);
            }
        }
Exemple #3
0
        public void queryInventory()
        {
            if (!IsDevice())
            {
                return;
            }
            IntPtr methodId = AndroidJNI.GetMethodID(_plugin.GetRawClass(), "queryInventory", "()V");

            AndroidJNI.CallVoidMethod(_plugin.GetRawObject(), methodId, new jvalue[] { });
        }
Exemple #4
0
    void Awake()
    {
        _instance = this;
#if UNITY_ANDROID && ENABLE_PLUGIN
        android = new AndroidJavaObject(ObjectClassPath);
        android.Call("init", gameObject.name, "NativeUIReceiveAgentEvent");
        arraylist      = new AndroidJavaObject("java.util.ArrayList");
        ptrMethodAdd   = AndroidJNI.GetMethodID(arraylist.GetRawClass(), "add", "(Ljava/lang/Object;)Z");
        ptrMethodClear = AndroidJNI.GetMethodID(arraylist.GetRawClass(), "clear", "()V");
#endif
    }
    private void                    _OpenForRead(string[] permissions, int handle)
    {
        object[] args = new object[2] {
            handle,
            new AndroidJavaObject(AndroidJNIHelper.ConvertToJNIArray(permissions))
        };
        IntPtr method_ptr = AndroidJNI.GetMethodID(android.GetRawClass(),
                                                   "OpenForRead", Method_intStringArraySigniture);

        AndroidJNI.CallVoidMethod(android.GetRawObject(), method_ptr, AndroidJNIHelper.CreateJNIArgArray(args));
        AndroidJNI.DeleteLocalRef(method_ptr);
    }
Exemple #6
0
        public void init(Options options)
        {
            if (!IsDevice())
            {
                // Fake init process in the editor. For test purposes
                OpenIAB.EventManager.SendMessage("OnBillingSupported", "");
                return;
            }

            using (var j_optionsBuilder = new AndroidJavaObject("org.onepf.oms.OpenIabHelper$Options$Builder"))
            {
                var clazz  = j_optionsBuilder.GetRawClass();
                var objPtr = j_optionsBuilder.GetRawObject();

                j_optionsBuilder.Call <AndroidJavaObject>("setDiscoveryTimeout", options.discoveryTimeoutMs)
                .Call <AndroidJavaObject>("setCheckInventory", options.checkInventory)
                .Call <AndroidJavaObject>("setCheckInventoryTimeout", options.checkInventoryTimeoutMs)
                .Call <AndroidJavaObject>("setVerifyMode", (int)options.verifyMode)
                .Call <AndroidJavaObject>("setStoreSearchStrategy", (int)options.storeSearchStrategy);

                if (options.samsungCertificationRequestCode > 0)
                {
                    j_optionsBuilder.Call <AndroidJavaObject>("setSamsungCertificationRequestCode", options.samsungCertificationRequestCode);
                }

                foreach (var pair in options.storeKeys)
                {
                    j_optionsBuilder.Call <AndroidJavaObject>("addStoreKey", pair.Key, pair.Value);
                }

                var addPreferredStoreNameMethod = AndroidJNI.GetMethodID(clazz, "addPreferredStoreName", "([Ljava/lang/String;)Lorg/onepf/oms/OpenIabHelper$Options$Builder;");
                var prms = new jvalue[1];
                prms[0].l = ConvertToStringJNIArray(options.prefferedStoreNames);
                AndroidJNI.CallObjectMethod(objPtr, addPreferredStoreNameMethod, prms);

                var addAvailableStoreNameMethod = AndroidJNI.GetMethodID(clazz, "addAvailableStoreNames", "([Ljava/lang/String;)Lorg/onepf/oms/OpenIabHelper$Options$Builder;");
                prms      = new jvalue[1];
                prms[0].l = ConvertToStringJNIArray(options.availableStoreNames);
                AndroidJNI.CallObjectMethod(objPtr, addAvailableStoreNameMethod, prms);

                // Build options instance
                var buildMethod = AndroidJNI.GetMethodID(clazz, "build", "()Lorg/onepf/oms/OpenIabHelper$Options;");
                var j_options   = AndroidJNI.CallObjectMethod(objPtr, buildMethod, new jvalue[0]);

                // UnityPlugin.initWithOptions(OpenIabHelper.Options options);
                var initWithOptionsMethod = AndroidJNI.GetMethodID(_plugin.GetRawClass(), "initWithOptions", "(Lorg/onepf/oms/OpenIabHelper$Options;)V");
                prms      = new jvalue[1];
                prms[0].l = j_options;
                AndroidJNI.CallVoidMethod(_plugin.GetRawObject(), initWithOptionsMethod, prms);
            }
        }
    void Awake()
    {
#if UNITY_ANDROID && ENABLE_PLUGIN
        android = new AndroidJavaObject(ObjectClassPath);
        android.Call("init", gameObject.name, "FacebookAgentReceiveAgentEvent");

        logMapObject = new AndroidJavaObject("android.os.Bundle");
        logMethodID  = AndroidJNIHelper.GetMethodID(logMapObject.GetRawClass(), "putString",
                                                    "(Ljava/lang/String;Ljava/lang/String;)V");
        logClearID         = AndroidJNIHelper.GetMethodID(logMapObject.GetRawClass(), "clear", "()V");
        logMethodByteArray = AndroidJNIHelper.GetMethodID(logMapObject.GetRawClass(), "putByteArray",
                                                          "(Ljava/lang/String;[B)V");
#endif
        _instance = this;
    }
Exemple #8
0
    void Awake()
    {
        _instance = this;
#if UNITY_ANDROID && ENABLE_PLUGIN
        android = new AndroidJavaObject(ObjectClassPath);
        int clients = 1;
        if (EnableCloudSave)
        {
            clients |= 2;
        }
        android.Call("init", gameObject.name, "PlayServicesReceiveAgentEvent", clients);
        handleSaveStatePtr         = AndroidJNIHelper.GetMethodID(android.GetRawClass(), "UpdateState", "(I[B)V");
        handleSaveStateImmedatePtr = AndroidJNIHelper.GetMethodID(android.GetRawClass(), "UpdateStateImmediate", "(II[B)V");
#endif
    }
        public static AndroidJavaObject ConvertToHashMap(IDictionary <string, string> stringStringDictionary)
        {
            if (stringStringDictionary == null)
            {
                return(null);
            }

            var objHashMap = new AndroidJavaObject("java.util.HashMap");

            System.IntPtr methodPut = AndroidJNIHelper.GetMethodID(objHashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

            object[] args = new object[2];
            foreach (KeyValuePair <string, string> keyValuePair in stringStringDictionary)
            {
                using (AndroidJavaObject javaStringKey = new AndroidJavaObject(JavaStringClass, keyValuePair.Key))
                {
                    using (AndroidJavaObject javaStringValue = new AndroidJavaObject(JavaStringClass, keyValuePair.Value))
                    {
                        args[0] = javaStringKey;
                        args[1] = javaStringValue;
                        AndroidJNI.CallObjectMethod(objHashMap.GetRawObject(), methodPut, AndroidJNIHelper.CreateJNIArgArray(args));
                    }
                }
            }

            return(objHashMap);
        }
Exemple #10
0
        private static AndroidJavaObject hashtable2JavaMap(Hashtable map)
        {
            AndroidJavaObject javaMap   = new AndroidJavaObject("java.util.HashMap");
            IntPtr            putMethod = AndroidJNIHelper.GetMethodID(javaMap.GetRawClass(), "put", "Ljava.lang.Object;(Ljava.lang.Object;Ljava.lang.Object;)", false);

            foreach (string key in map.Keys)
            {
                object value   = map[key];
                object javaKey = getJavaString(key.ToString());
                object javaValue;
                if (value.GetType() == typeof(Hashtable))
                {
                    javaValue = hashtable2JavaMap((Hashtable)value);
                }
                else
                {
                    javaValue = getJavaString(value.ToString());
                }

                object[] arr = new object[2];
                arr[0] = javaKey; arr[1] = javaValue;

                jvalue[] param = AndroidJNIHelper.CreateJNIArgArray(arr);
                AndroidJNI.CallObjectMethod(javaMap.GetRawObject(), putMethod, param);
            }
            return(javaMap);
        }
Exemple #11
0
    /// <summary>
    /// Set up the video player with the movie surface texture id.
    /// </summary>
    AndroidJavaObject StartVideoPlayerOnTextureId(int texWidth, int texHeight, string mediaPath)
    {
        Debug.Log("MoviePlayer: StartVideoPlayerOnTextureId");

        Debug.Log("StartVideoPlayerOnTextureId: texWidth: " + textureWidth + ", texheight: " + textureHeight);
        OVR_Media_Surface_SetTextureParms(textureWidth, textureHeight);

        IntPtr            androidSurface = OVR_Media_Surface_GetObject();
        AndroidJavaObject mediaPlayer    = new AndroidJavaObject("android/media/MediaPlayer");

        // Can't use AndroidJavaObject.Call() with a jobject, must use low level interface
        //mediaPlayer.Call("setSurface", androidSurface);
        IntPtr setSurfaceMethodId = AndroidJNI.GetMethodID(mediaPlayer.GetRawClass(), "setSurface", "(Landroid/view/Surface;)V");

        jvalue[] parms = new jvalue[1];
        parms[0]   = new jvalue();
        parms[0].l = androidSurface;
        AndroidJNI.CallVoidMethod(mediaPlayer.GetRawObject(), setSurfaceMethodId, parms);

        try {
            mediaPlayer.Call("setDataSource", mediaPath);
            mediaPlayer.Call("prepare");
            mediaPlayer.Call("setLooping", true);
            mediaPlayer.Call("start");

            Debug.Log("Getting duration");
            durationMs = mediaPlayer.Call <int>("getDuration");
            Debug.Log("duration: " + durationMs);
        } catch (Exception e) {
            Debug.Log("Failed to start mediaPlayer with message " + e.Message);
        }

        return(mediaPlayer);
    }
Exemple #12
0
        protected internal static AndroidJavaObject GetHashMapFromDictionary(Dictionary <string, object> dict)
        {
            // quick out if nothing in the dict param
            if (dict == null || dict.Count <= 0)
            {
                return(null);
            }

            AndroidJavaObject hashMap   = new AndroidJavaObject("java.util.HashMap");
            IntPtr            putMethod = AndroidJNIHelper.GetMethodID(hashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

            object[] args = new object[2];
            foreach (KeyValuePair <string, object> kvp in dict)
            {
                using (var key = new AndroidJavaObject("java.lang.String", kvp.Key))
                {
                    using (var value = new AndroidJavaObject("java.lang.String", kvp.Value))
                    {
                        args[0] = key;
                        args[1] = value;
                        AndroidJNI.CallObjectMethod(hashMap.GetRawObject(), putMethod, AndroidJNIHelper.CreateJNIArgArray(args));
                    }
                }
            }

            return(hashMap);
        }
    /// <summary>
    /// Sets the surface for our GeckoView plugin when the OVROverlay is ready and the plugin is initialized
    /// Also we sign up for the sign in event so we can load the first webpage/initialize history
    /// when the user signs ins
    /// </summary>
    /// <returns>The start function</returns>
    private IEnumerator Start()
    {
#if UNITY_EDITOR
        yield break;
#endif
        // Wait for surface to be available.
        while (_overlay.externalSurfaceObject == IntPtr.Zero || _ajc == null)
        {
            yield return(null);
        }
        Debug.Log("Browser Start!");
        var pluginClass     = _ajc.GetRawClass();
        var pluginObject    = _ajc.GetRawObject();
        var surfaceMethodId = AndroidJNI.GetMethodID(pluginClass, "PassSurface", "(Landroid/view/Surface;)V");

        AndroidJNI.CallVoidMethod(pluginObject, surfaceMethodId,
                                  new jvalue[] { new jvalue {
                                                     l = _overlay.externalSurfaceObject
                                                 } });

        //try
        //{
        //    AndroidJNI.DeleteLocalRef(pluginClass);
        //    AndroidJNI.DeleteLocalRef(pluginObject);
        //}
        //catch
        //{
        //}

        OnGeckoViewReady();
    }
Exemple #14
0
        public static string safeCallStringMethod(AndroidJavaObject javaObject, string methodName, params object[] args)
        {
            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);
        }
	private static AndroidJavaObject CreateJavaMapFromDictainary(IDictionary<string, string> parameters)
	{
		AndroidJavaObject javaMap = new AndroidJavaObject("java.util.HashMap");
		IntPtr putMethod = AndroidJNIHelper.GetMethodID(
			javaMap.GetRawClass(), "put",
				"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

		object[] args = new object[2];
		foreach (KeyValuePair<string, string> kvp in parameters)
		{

			using (AndroidJavaObject k = new AndroidJavaObject(
				"java.lang.String", kvp.Key))
			{
				using (AndroidJavaObject v = new AndroidJavaObject(
					"java.lang.String", kvp.Value))
				{
					args[0] = k;
					args[1] = v;
					AndroidJNI.CallObjectMethod(javaMap.GetRawObject(),
							putMethod, AndroidJNIHelper.CreateJNIArgArray(args));
				}
			}
		}

		return javaMap;
	}
Exemple #16
0
        /**
         * Unity AndroidJavaObject throws an exception if a call from Java returns null
         * so we have our own implementation.
         */
        public static AndroidJavaObject cjoReturningNull(
            this AndroidJavaObject javaObject, string methodName, params object[] args
            )
        {
            if (args == null)
            {
                args = new object[1];
            }
            var methodId = AndroidJNIHelper.GetMethodID <AndroidJavaObject>(
                javaObject.GetRawClass(), methodName, args, false
                );
            var jniArgArray = AndroidJNIHelper.CreateJNIArgArray(args);

            try {
                var returned = AndroidJNI.CallObjectMethod(
                    javaObject.GetRawObject(), methodId, jniArgArray
                    );
                if (returned == IntPtr.Zero)
                {
                    return(null);
                }
                else
                {
                    try { return(ajoCreator(new object[] { returned })); }
                    finally { AndroidJNI.DeleteLocalRef(returned); }
                }
            }
            finally {
                AndroidJNIHelper.DeleteJNIArgArray(args, jniArgArray);
            }
        }
Exemple #17
0
        public static string CallStr(this AndroidJavaObject ajo, string methodName,
                                     params object[] args)
        {
#if UNITY_2018_2_OR_NEWER
            // A fix for a regression issue introduced in Unity 2018.2
            // Details: https://issuetracker.unity3d.com/issues/android-androidjavaobject-dot-call-crashes-with-fatal-signal-11-sigsegv

            if (args == null)
            {
                args = new object[] { null };
            }
            IntPtr   methodID = AndroidJNIHelper.GetMethodID <string>(ajo.GetRawClass(), methodName, args, false);
            jvalue[] jniArgs  = AndroidJNIHelper.CreateJNIArgArray(args);

            try
            {
                IntPtr returnValue = AndroidJNI.CallObjectMethod(ajo.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(CallSafe <string>(ajo, methodName, args));
#endif
        }
        int Read(AndroidJavaObject javaObject, byte[] buffer, int offset, int count)
        {
            var    args     = new object[] { buffer, offset, count };
            IntPtr methodID = AndroidJNIHelper.GetMethodID <int>(javaObject.GetRawClass(), "read", args, false);

            jvalue[] array = AndroidJNIHelper.CreateJNIArgArray(args);
            try
            {
                var readLen = AndroidJNI.CallIntMethod(javaObject.GetRawObject(), methodID, array);
                if (readLen > 0)
                {
                    var temp = AndroidJNI.FromByteArray(array[0].l);
                    Array.Copy(temp, offset, buffer, offset, readLen);
                }

                /*
                 * for (var i = offset; i < readLen; ++i)
                 * {
                 * buffer[i] = AndroidJNI.GetByteArrayElement(array[0].l, i);
                 * }
                 */
                return(readLen);
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, array);
            }
        }
        public static AndroidJavaObject CreateJavaHashMapFromDictionary(IDictionary <string, string> keysDict)
        {
            if (keysDict == null)
            {
                return(null);
            }

            AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap");

            // Call 'put' via the JNI instead of using helper classes to avoid:
            //  "JNI: Init'd AndroidJavaObject with null ptr!"
            System.IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put",
                                                                    "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

            object[] args = new object[2];
            if (keysDict != null)
            {
                foreach (KeyValuePair <string, string> kvp in keysDict)
                {
                    using (AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key + ""))
                    {
                        using (AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value + ""))
                        {
                            args[0] = k;
                            args[1] = v;
                            AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(),
                                                        method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
                        }
                    }
                }
            }
            return(obj_HashMap);
        }
Exemple #20
0
    public override void logEvent(string eventId, Hashtable parameters)
    {
        using (AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap"))
        {
            // Call 'put' via the JNI instead of using helper classes to avoid:
            //  "JNI: Init'd AndroidJavaObject with null ptr!"
            IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put",
                                                             "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

            object[] args = new object[2];
            foreach (DictionaryEntry kvp in parameters)
            {
                using (AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key + ""))
                {
                    using (AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value + ""))
                    {
                        args[0] = k;
                        args[1] = v;
                        AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(),
                                                    method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
                    }
                }
            }
            cls_FlurryAgent.CallStatic("logEvent", eventId, obj_HashMap);
        }
    }
Exemple #21
0
    /// <summary>
    ///  Helper method for creating a java HashMap from a c# dictionary
    /// </summary>
    /// <param name="dictionary">dictionary to use for HashMap creation</param>
    /// <returns>AndroidJovaObject referencing a java HashMap</returns>
    protected AmazonJavaWrapper DictionaryToAndroidHashMap(Dictionary <String, String> dictionary)
    {
        AndroidJNI.PushLocalFrame(10);

        AndroidJavaObject javaHashMap = new AndroidJavaObject("java.util.HashMap");

        //revert to manual JNI calls due to apparent bug in calling put on a hashmap object
        //from the AndroidJavaObject class
        IntPtr putMethod = AndroidJNIHelper.GetMethodID(javaHashMap.GetRawClass(), "put",
                                                        "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

        object[] keyValSet = new object[2];

        foreach (KeyValuePair <string, string> kv in dictionary)
        {
            using (AndroidJavaObject key = new AndroidJavaObject("java.lang.String", kv.Key)){
                using (AndroidJavaObject value = new AndroidJavaObject("java.lang.String", kv.Value)){
                    keyValSet[0] = key;
                    keyValSet[1] = value;
                    jvalue[] methodValues = AndroidJNIHelper.CreateJNIArgArray(keyValSet);
                    AndroidJNI.CallObjectMethod(javaHashMap.GetRawObject(),
                                                putMethod, methodValues);
                }
            }
        }
        AndroidJNI.PopLocalFrame(System.IntPtr.Zero);
        return(new AmazonJavaWrapper(javaHashMap));
    }
    private static AndroidJavaObject CreateAndroidTargetInfo(Dictionary <string, List <string> > info)
    {
        AndroidJavaObject androidJavaObject = new AndroidJavaObject("java.util.HashMap");

        foreach (KeyValuePair <string, List <string> > item in info)
        {
            AndroidJavaObject androidJavaObject2 = new AndroidJavaObject("java.util.LinkedList");
            foreach (string item2 in item.Value)
            {
                AndroidJavaObject androidJavaObject3 = new AndroidJavaObject("java.lang.String", item2);
                androidJavaObject2.Call <bool>("add", new object[1]
                {
                    androidJavaObject3
                });
            }
            AndroidJavaObject androidJavaObject4 = new AndroidJavaObject("java.lang.String", item.Key);
            IntPtr            methodID           = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
            AndroidJNI.CallObjectMethod(args: AndroidJNIHelper.CreateJNIArgArray(new object[2]
            {
                androidJavaObject4,
                androidJavaObject2
            }), obj: androidJavaObject.GetRawObject(), methodID: methodID);
        }
        return(androidJavaObject);
    }
    // Calls a custom Graph API method with the key/value pairs in the Dictionary.  Pass in a null dictionary if no parameters are needed.
    public static void graphRequest(string graphPath, string httpMethod, Dictionary <string, string> parameters)
    {
        if (Application.platform != RuntimePlatform.Android)
        {
            return;
        }

        // load up the Bundle
        using (var bundle = new AndroidJavaObject("android.os.Bundle"))
        {
            var putStringMethod = AndroidJNI.GetMethodID(bundle.GetRawClass(), "putString", "(Ljava/lang/String;Ljava/lang/String;)V");
            var args            = new object[2];

            // add all our dictionary elements into the Bundle
            if (parameters != null)
            {
                foreach (var kv in parameters)
                {
                    args[0] = new AndroidJavaObject("java.lang.String", kv.Key);
                    args[1] = new AndroidJavaObject("java.lang.String", kv.Value);
                    AndroidJNI.CallObjectMethod(bundle.GetRawObject(), putStringMethod, AndroidJNIHelper.CreateJNIArgArray(args));
                }
            }

            // call off to java land
            _facebookPlugin.Call("graphRequest", graphPath, httpMethod, bundle);
        }
    }
    // Supposed to be called once at voice initialization.
    // Otherwise recreate native object (instead of adding 'set callback' method to java interface)
    public void SetCallback(Action <short[]> callback, Voice.LocalVoice localVoice)
    {
        if (audioIn != null)
        {
            Dispose();
        }
        var voiceFrameSize = ((Voice.LocalVoiceFramed)localVoice).FrameSize;

        // setting to voice FrameSize lets to avoid framing procedure
        javaBuf = AndroidJNI.NewGlobalRef(AndroidJNI.NewShortArray(voiceFrameSize));

        this.callback = new DataCallback(callback, javaBuf);
        audioIn       = new AndroidJavaObject("com.exitgames.photon.audioinaec.AudioInAEC");
        bool aecAvailable = audioIn.Call <bool>("AECIsAvailable");
        int  minBufSize   = audioIn.Call <int>("GetMinBufferSize", SamplingRate, Channels);

        Debug.LogFormat("AndroidAudioInAEC: AndroidJavaObject created: aecAvailable: {0}, minBufSize: {1}", aecAvailable, minBufSize);

        AndroidJavaClass  app      = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject activity = app.GetStatic <AndroidJavaObject>("currentActivity");
        // Set buffer IntPtr reference separately via pure jni call, pass other values and start capture via AndroidJavaObject helper

        var  meth = AndroidJNI.GetMethodID(audioIn.GetRawClass(), "SetBuffer", "([S)Z");
        bool ok   = AndroidJNI.CallBooleanMethod(audioIn.GetRawObject(), meth, new jvalue[] { new jvalue()
                                                                                              {
                                                                                                  l = javaBuf
                                                                                              } });

        if (ok)
        {
            ok = audioIn.Call <bool>("Start", activity, this.callback, SamplingRate, Channels, minBufSize * 4, aecAvailable);
        }

        Debug.LogFormat("AndroidAudioInAEC: AndroidJavaObject started: {0}, buffer size: {1}, sampling rate: {2}, channels: {3}, record buffer size: {4}, aec: {5}", ok, voiceFrameSize, SamplingRate, Channels, minBufSize * 4, aecAvailable);
    }
Exemple #25
0
            public void SetDeviceConfiguration(WearableDeviceConfig config)
            {
                if (_wearablePlugin != null)
                {
                    bool[] sensors = new bool[WearableConstants.SensorIds.Length];
                    for (int i = 0; i < WearableConstants.SensorIds.Length; i++)
                    {
                        sensors[i] = config.GetSensorConfig(WearableConstants.SensorIds[i]).isEnabled;
                    }
                    IntPtr sensorsJava = AndroidJNIHelper.ConvertToJNIArray(sensors);

                    bool[] gestures = new bool[WearableConstants.GestureIds.Length - 1];                   // -1 to Exclude .None
                    for (int i = 1; i < WearableConstants.GestureIds.Length; i++)
                    {
                        gestures[i - 1] = config.GetGestureConfig(WearableConstants.GestureIds[i]).isEnabled;
                    }
                    IntPtr gesturesJava = AndroidJNIHelper.ConvertToJNIArray(gestures);

                    // The AndroidJavaObject.Call method doesn't support arrays, so we have to convert & pass them more deliberately.
                    jvalue[] args = new jvalue[4];
                    args[0].l = sensorsJava;
                    args[1].l = gesturesJava;
                    args[2].i = (int)config.updateInterval;
                    IntPtr setMethod = AndroidJNIHelper.GetMethodID(_wearablePlugin.GetRawClass(), SetDeviceConfigurationMethod);
                    AndroidJNI.CallVoidMethod(_wearablePlugin.GetRawObject(), setMethod, args);
                }
            }
 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
                                                                                        } });
             byte[] data = AndroidJNI.FromByteArray(array);
             Array.Copy(data, 0, buffer, offset, ret);
         }
         finally
         {
             if (array != IntPtr.Zero)
             {
                 AndroidJNI.DeleteLocalRef(array);
             }
         }
         return(ret);
     }
 }
Exemple #27
0
        public static AndroidJavaObject CreateJavaMapFromDictionary(IDictionary <string, string> parameters)
        {
            var javaMap   = new AndroidJavaObject("java.util.HashMap");
            var putMethod = AndroidJNIHelper.GetMethodID(
                javaMap.GetRawClass(), "put",
                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

            var args = new object[2];

            foreach (var kvp in parameters)
            {
                using (var k = new AndroidJavaObject(
                           "java.lang.String", kvp.Key))
                {
                    using (var v = new AndroidJavaObject(
                               "java.lang.String", kvp.Value))
                    {
                        args[0] = k;
                        args[1] = v;
                        AndroidJNI.CallObjectMethod(javaMap.GetRawObject(),
                                                    putMethod, AndroidJNIHelper.CreateJNIArgArray(args));
                    }
                }
            }

            return(javaMap);
        }
    public void CreateJavaAndroidObject()
    {
        //Metodo start de CDAux llama a InstantiateJavaObject
        cdaux.InstantiateJavaObject("com.tfg.marta.androidplugin2.PluginClass");

        Assert.That(cdaux.javaObject.GetRawClass(), Is.EqualTo(javaobjAux.GetRawClass()));
    }
Exemple #29
0
    /// <summary>
    /// Set up the video player with the movie surface texture id.
    /// </summary>
    AndroidJavaObject StartVideoPlayerOnTextureId(IntPtr texId, int texWidth, int texHeight, string mediaPath)
    {
        Debug.Log("MoviePlayer: SetUpVideoPlayer");

        IntPtr androidSurface = OVR_Media_Surface(texId, texWidth, texHeight);

        Debug.Log("MoviePlayer: SetUpVideoPlayer after create surface");

        AndroidJavaObject mediaPlayer = new AndroidJavaObject("android/media/MediaPlayer");

        // Can't use AndroidJavaObject.Call() with a jobject, must use low level interface
        //mediaPlayer.Call("setSurface", androidSurface);
        IntPtr setSurfaceMethodId = AndroidJNI.GetMethodID(mediaPlayer.GetRawClass(), "setSurface", "(Landroid/view/Surface;)V");

        jvalue[] parms = new jvalue[1];
        parms[0]   = new jvalue();
        parms[0].l = androidSurface;
        AndroidJNI.CallVoidMethod(mediaPlayer.GetRawObject(), setSurfaceMethodId, parms);

        try
        {
            mediaPlayer.Call("setDataSource", mediaPath);
            mediaPlayer.Call("prepare");
            mediaPlayer.Call("setLooping", true);
            mediaPlayer.Call("start");
        }
        catch (Exception e)
        {
            Debug.Log("Failed to start mediaPlayer with message " + e.Message);
        }

        return(mediaPlayer);
    }
Exemple #30
0
    //turn a dictionary into hashmap, to pass it in JNI
    private static AndroidJavaObject ConvertHashMap(Dictionary <string, string> dict)
    {
        AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap");

        IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put",
                                                         "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

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

        object[] args = new object[2];
        foreach (KeyValuePair <string, string> kvp in dict)
        {
            using (AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key))
            {
                using (AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value))
                {
                    args[0] = k;
                    args[1] = v;
                    AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(),
                                                method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
                }
            }
        }
        return(obj_HashMap);
    }