public JSONObject(string buffer)
        {
#if VERBOSE_LOGGING
            Debug.Log(MethodBase.GetCurrentMethod().Name);
#endif
            JNIFind();
            if (_jcJsonObject == IntPtr.Zero)
            {
                Debug.LogError("_jcJsonObject is not initialized");
                return;
            }
            if (_jmConstructor2 == IntPtr.Zero)
            {
                Debug.LogError("_jmConstructor2 is not initialized");
                return;
            }

            _instance = AndroidJNI.AllocObject(_jcJsonObject);
            if (_instance == IntPtr.Zero)
            {
                Debug.LogError("Failed to allocate JSONObject");
                return;
            }

            IntPtr arg1 = AndroidJNI.NewStringUTF(buffer);
            AndroidJNI.CallVoidMethod(_instance, _jmConstructor2, new jvalue[] { new jvalue()
                                                                                 {
                                                                                     l = arg1
                                                                                 } });
            AndroidJNI.DeleteLocalRef(arg1);
        }
    private void hapticFeedbackWave(long[] times)
    {
        var jVibratorService = new AndroidJavaClass("android.content.Context").GetStatic <string>("VIBRATOR_SERVICE");
        var jVibrator        = jCurrentActivity.Call <AndroidJavaObject>("getSystemService", jVibratorService);

        if (apiLevel >= 26)
        {
            var      jEffectCls = new AndroidJavaClass("android.os.VibrationEffect");
            IntPtr   jTimes     = AndroidJNI.ToLongArray(times);
            jvalue[] jParams1   = new jvalue[2];
            jParams1[0].l = jTimes;
            jParams1[1].i = -1;
            IntPtr jmidCreateWaveForm = AndroidJNIHelper.GetMethodID(jEffectCls.GetRawClass(), "createWaveform", "([JI)Landroid/os/VibrationEffect;", true);
            var    jEffect            = AndroidJNI.CallStaticObjectMethod(jEffectCls.GetRawClass(), jmidCreateWaveForm, jParams1);

            IntPtr   jmidVibrate = AndroidJNIHelper.GetMethodID(jVibrator.GetRawClass(), "vibrate", "(Landroid/os/VibrationEffect;)V");
            jvalue[] jParams2    = new jvalue[2];
            jParams2[0].l = jEffect;
            AndroidJNI.CallVoidMethod(jVibrator.GetRawObject(), jmidVibrate, jParams2);
        }
        else
        {
            jVibrator.Call("vibrate", times);
        }
    }
        public JSONObject()
        {
#if VERBOSE_LOGGING
            Debug.Log(MethodBase.GetCurrentMethod().Name);
#endif
            JNIFind();
            if (_jcJsonObject == IntPtr.Zero)
            {
                Debug.LogError("_jcJsonObject is not initialized");
                return;
            }
            if (_jmConstructor == IntPtr.Zero)
            {
                Debug.LogError("_jmConstructor is not initialized");
                return;
            }

            _instance = AndroidJNI.AllocObject(_jcJsonObject);
            if (_instance == IntPtr.Zero)
            {
                Debug.LogError("Failed to allocate JSONObject");
                return;
            }

            AndroidJNI.CallVoidMethod(_instance, _jmConstructor, new jvalue[0]);
        }
    // 关闭Android端程序
    static private void CloseAndroidAPP()
    {
        Debug.Log("jianzhao CloseAndroidAPP!!!");
        //AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        //AndroidJavaObject androidJavaObject = androidJavaClass.GetStatic<AndroidJavaObject>("currentActivity");
        //javaPlayer = new AndroidJavaObject("com/compilelife/mediacodecexample/MainActivity");
        if (javaPlayer != null)
        {
            IntPtr methodId = IntPtr.Zero;
            methodId = AndroidJNI.GetMethodID(javaPlayer.GetRawClass(), "UnityClose", "(I)V");
            if (methodId != IntPtr.Zero)
            {
                jvalue[] parms = new jvalue[1];
                parms[0] = new jvalue();
                int i = 203;
                parms[0].i = i;
                AndroidJNI.CallVoidMethod(javaPlayer.GetRawObject(), methodId, parms);
            }
            else
            {
                Debug.Log("jianzhao CloseAndroidAPP::methodId is null!!!");
            }
        }
        else
        {
            Debug.Log("jianzhao CloseAndroidAPP::javaPlayer is null!!!");
        }

        Application.Quit();
    }
Beispiel #5
0
    private void CaptureFrame(int textureID)
    {
        if (capturingObject == IntPtr.Zero)
        {
            return;
        }

        jvalue[] args = new jvalue[1];
        args[0].i = textureID;
        AndroidJNI.CallVoidMethod(capturingObject, captureFrameMethodID, args);

        AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
        string           action      = intentClass.GetStatic <string>("ACTION_MEDIA_SCANNER_SCAN_FILE");

        // Intent intentObject = new Intent(action);
        AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent", action);

        // Uri uriObject = Uri.parse("file:" + filePath);
        AndroidJavaClass  uriClass  = new AndroidJavaClass("android.net.Uri");
        AndroidJavaObject uriObject = uriClass.CallStatic <AndroidJavaObject>("parse", "file:" + fileFullPath);

        // intentObject.setData(uriObject);
        intentObject.Call <AndroidJavaObject>("setData", uriObject);

        // this.sendBroadcast(intentObject);

        /* AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         * AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");*/
        playerActivityContext.Call("sendBroadcast", intentObject);
    }
    // 将AndroidSurface通过JNI传递过Android程序
    private void passSurfaceToAndroid()
    {
        //AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.example.lib4unity.PlayerActivity");
        //AndroidJavaObject androidJavaObject = androidJavaClass.GetStatic<AndroidJavaObject>("m_instance");
        AndroidJavaClass  androidJavaClass  = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject androidJavaObject = androidJavaClass.GetStatic <AndroidJavaObject>("currentActivity");

        // vrdemo/medialab/huawei/com/demoplayer/Vr2Player 这里是jar包的格式
        // com.compilelife.mediacodecexample
        javaPlayer = new AndroidJavaObject("com/mmc/Exp4/MainActivity");
        if (javaPlayer == null)
        {
            Debug.Log("jianzhao javaPlayer is null!!");
        }

        javaPlayer.Call <int>("init", androidJavaObject);
        IntPtr methodId = AndroidJNI.GetMethodID(javaPlayer.GetRawClass(), "setSurface", "(Landroid/view/Surface;)V");

        //IntPtr setSurfaceMethodId = AndroidJNI.GetMethodID(javaPlayer.GetRawClass(), "setSurface", "(Landroid/graphics/SurfaceTexture;)V");
        jvalue[] parms = new jvalue[1];
        parms[0]   = new jvalue();
        parms[0].l = androidSurface;
        //AndroidJNI.CallObjectMethod(javaPlayer.GetRawObject(), setSurfaceMethodId, parms);
        AndroidJNI.CallVoidMethod(javaPlayer.GetRawObject(), methodId, parms);
        Debug.Log("jianzhao unity setSurfaceMethodId done!");
    }
        public void initiateItemDataRequest(string[] productIds)
        {
#if UNITY_ANDROID
            var initMethod = AndroidJNI.GetMethodID(amazon.GetRawClass(), "initiateItemDataRequest", "([Ljava/lang/String;)V");
            AndroidJNI.CallVoidMethod(amazon.GetRawObject(), initMethod, AndroidJNIHelper.CreateJNIArgArray(new object[] { productIds }));
#endif
        }
Beispiel #8
0
    private int[] GifToIntAA(byte[] bytes, int length)
    {
        AndroidJavaClass bmf = new AndroidJavaClass("android.graphics.BitmapFactory");
        AndroidJavaClass bm  = new AndroidJavaClass("android.graphics.Bitmap");
        // this bitmapfactory class method returns a Bitmap object
        AndroidJavaObject bmo = bmf.CallStatic <AndroidJavaObject>("decodeByteArray", new object[] { bytes, 0, length });
        // we can figure out the width and height of the gif data
        int h = bmo.Call <int>("getHeight", new object[] { });
        int w = bmo.Call <int>("getWidth", new object[] { });

        wh = new Vector2Int(w, h); // set the global wh for offsetment
                                   // the trick is getting the pixels without calling the JNI to often i.e. _getPixel()_
                                   // setup java inputs for BitMap.getPixels
        System.IntPtr pixs = AndroidJNI.NewIntArray(h * w);
        jvalue[]      gpargs;
        gpargs      = new jvalue[7];
        gpargs[0].l = pixs;
        gpargs[1].i = 0;
        gpargs[2].i = w;
        gpargs[3].i = 0;
        gpargs[4].i = 0;
        gpargs[5].i = w;
        gpargs[6].i = h;
        // this is the same as `bmo.getPixels(pixs,0,w,0,0,w,h)` but in raw AndroidJNI calls because pixs is a pointer to an int[] buffer
        AndroidJNI.CallVoidMethod(bmo.GetRawObject(), AndroidJNI.GetMethodID(bm.GetRawClass(), "getPixels", "([IIIIIII)V"), gpargs);
        return(AndroidJNI.FromIntArray(pixs));
    }
 private void onFrame(int frameIndex)
 {
     frameHandler(frameIndex, nativeTexture);
     if (!matrixSet)
     {
         Dispatcher.Dispatch(
             Dispatcher.Target.RenderThread,
             () => {
             surfaceTexture.Call(@"updateTexImage");
             // Update UV transform
             var args   = new jvalue[1];
             args [0].l = transformMatrix;
             AndroidJNI.CallVoidMethod(surfaceTexture.GetRawObject(), getTransformMatrixMethod, args);
             // Inject into render material
             var transform = AndroidJNIHelper.ConvertFromJNIArray <float[]> (transformMatrix);
             for (var j = 0; j < 4; j++)
             {
                 for (var i = 0; i < 4; i++)
                 {
                     matrix [i, j] = transform [i + 4 * j];
                 }
             }
             renderMaterial.SetMatrix("_SampleTransform", matrix);
             matrixSet = true;
         }
             );
     }
 }
    /// <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();
    }
Beispiel #11
0
 public override void ResetAudioFocus()
 {
     if (m_Video != null)
     {
         if (m_Method_SetFocusProps != System.IntPtr.Zero &&
             m_Method_SetFocusEnabled != System.IntPtr.Zero &&
             m_Method_SetFocusRotation != System.IntPtr.Zero)
         {
             m_Value2[0].f = 0f;
             m_Value2[1].f = 90f;
             AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetFocusProps, m_Value2);
             m_Value1[0].z = false;
             AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetFocusEnabled, m_Value1);
             m_Value4[0].f = 0f;
             m_Value4[1].f = 0f;
             m_Value4[2].f = 0f;
             m_Value4[3].f = 1f;
             AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetFocusRotation, m_Value4);
         }
         else
         {
             m_Video.Call("SetFocusProps", 0f, 90f);
             m_Video.Call("SetFocusEnabled", false);
             m_Video.Call("SetFocusRotation", 0f, 0f, 0f, 1f);
         }
     }
 }
        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
        }
        public override void Update()
        {
            if (m_Video != null)
            {
                if (m_Method_Update != System.IntPtr.Zero)
                {
                    AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_Update, m_Value0);
                }
                else
                {
                    m_Video.Call("Update");
                }

                //				_lastError = (ErrorCode)( m_Video.Call<int>("GetLastErrorCode") );
                _lastError = (ErrorCode)(Native._GetLastErrorCode(m_iPlayerIndex));
            }

            UpdateSubtitles();

            if (Mathf.Approximately(m_DurationMs, 0f))
            {
#if DLL_METHODS
                m_DurationMs = (float)(Native._GetDuration(m_iPlayerIndex));
#else
                m_DurationMs = (float)(m_Video.Call <long>("GetDurationMs"));
#endif
//				if( m_DurationMs > 0.0f ) { Helper.LogInfo("Duration: " + m_DurationMs); }
            }
        }
    // Full access to any existing or new Facebook dialogs that get added.  See Facebooks documentation for parameters and dialog types
    public static void showDialog(string dialogType, 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.CallVoidMethod(bundle.GetRawObject(), putStringMethod, AndroidJNIHelper.CreateJNIArgArray(args));
                }
            }

            // call off to java land
            _facebookPlugin.Call("showDialog", dialogType, bundle);
        }
    }
Beispiel #15
0
        public void compress(Bitmap.CompressFormat format, int quality, ByteArrayOutputStream stream)
        {
            JNIFind();

            if (_instance == IntPtr.Zero)
            {
                Debug.LogError("_instance is not initialized");
                return;
            }
            if (_jmCompress == IntPtr.Zero)
            {
                Debug.LogError("_jmCompress is not initialized");
                return;
            }
            AndroidJNI.CallVoidMethod(_instance, _jmCompress, new jvalue[] { new jvalue()
                                                                             {
                                                                                 l = format.Instance
                                                                             }, new jvalue()
                                                                             {
                                                                                 i = quality
                                                                             }, new jvalue()
                                                                             {
                                                                                 l = stream.GetInstance()
                                                                             } });
        }
Beispiel #16
0
        private void UpdateCharastricsKeys(string addr, IntPtr device)
        {
            List <BleCharastericsKeyInfo> list = null;

            if (this.charastericsKeyInfos.TryGetValue(addr, out list))
            {
                return;
            }
            var blitCharaMethod = AndroidJNI.GetMethodID(this.bleDeviceCls, "blitChara", "()V");
            var getKeyNumMethod = AndroidJNI.GetMethodID(this.bleDeviceCls, "getKeysNum", "()I");
            var getServiceUuidFromKeysMethod = AndroidJNI.GetMethodID(this.bleDeviceCls,
                                                                      "getServiceUuidFromKeys", "(I)Ljava/lang/String;");
            var getCharastricUuidFromKeysMethod = AndroidJNI.GetMethodID(this.bleDeviceCls,
                                                                         "getCharastricUuidFromKeys", "(I)Ljava/lang/String;");

            // blit chara
            AndroidJNI.CallVoidMethod(device, blitCharaMethod, null);
            int num = AndroidJNI.CallIntMethod(device, getKeyNumMethod, null);

            if (num <= 0)
            {
                return;
            }
            list = new List <BleCharastericsKeyInfo>(num);
            for (int i = 0; i < num; ++i)
            {
                this.argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(i));
                string serviceUuid    = AndroidJNI.CallStringMethod(device, getServiceUuidFromKeysMethod, argBuilder.Build());
                string charastricUuid = AndroidJNI.CallStringMethod(device, getCharastricUuidFromKeysMethod, argBuilder.Build());
                var    keyInfo        = new BleCharastericsKeyInfo(addr, serviceUuid, charastricUuid);
                list.Add(keyInfo);
            }

            this.charastericsKeyInfos.Add(addr, list);
        }
Beispiel #17
0
        public void InvokeCallVoid(string name, string sig, params object[] args)
        {
            IntPtr methodID = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(this.raw), name, sig);

            jvalue[] jvalueArray = ConstructArgArray(args);
            AndroidJNI.CallVoidMethod(this.raw, methodID, jvalueArray);
        }
Beispiel #18
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);
                }
            }
Beispiel #19
0
    /// <summary>
    /// Parses the tango pose status.
    /// </summary>
    /// <param name="poseStatus">Pose status.</param>
    public static void ParseTangoPoseStatus(int poseStatus)
    {
        AndroidJavaObject tangoUxObject = GetTangoUxHelperObject();

        if (tangoUxObject != null)
        {
            // Replaced with the call to JNI to reduce memory allocations
            // tangoUxObject.Call("processPoseDataStatus", poseStatus);
            if (jniAttached != 1)
            {
                if (AndroidJNI.AttachCurrentThread() == 0)
                {
                    jniAttached = 1;
                }
            }

            if (jniAttached == 1)
            {
                if (val == null)
                {
                    val = new jvalue[1];
                }

                m_tangoUxHelper_processPoseDataStatus = AndroidJNI.GetMethodID(m_tangoUxHelper_class, "processPoseDataStatus", "(I)V");
                val[0].i = poseStatus;
                AndroidJNI.CallVoidMethod(m_tangoUxHelper_obj, m_tangoUxHelper_processPoseDataStatus, val);
            }
        }
    }
        public void InvokeCallVoid(string name, string sig, params object[] args)
        {
            IntPtr methodID = AndroidJNI.GetMethodID(RawClass, name, sig);

            jvalue[] array = ConstructArgArray(args);
            AndroidJNI.CallVoidMethod(raw, methodID, array);
        }
Beispiel #21
0
            public void removeScreenshot(OuyaModScreenshot screenshot)
            {
#if VERBOSE_LOGGING
                Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
                JNIFind();

                if (_instance == IntPtr.Zero)
                {
                    Debug.LogError("_instance is not initialized");
                    return;
                }
                if (_jmRemoveScreenshot == IntPtr.Zero)
                {
                    Debug.LogError("_jmRemoveScreenshot is not initialized");
                    return;
                }
                if (null == screenshot)
                {
                    Debug.LogError("bitmap is not initialized");
                    return;
                }
                if (screenshot.GetInstance() == IntPtr.Zero)
                {
                    Debug.LogError("screenshot.Instance is not initialized");
                    return;
                }

                IntPtr arg1 = screenshot.GetInstance();
                AndroidJNI.CallVoidMethod(_instance, _jmRemoveScreenshot, new jvalue[] { new jvalue()
                                                                                         {
                                                                                             l = arg1
                                                                                         } });
            }
Beispiel #22
0
            public void setMetadata(string metadata)
            {
#if VERBOSE_LOGGING
                Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
                JNIFind();

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

                IntPtr arg1 = AndroidJNI.NewStringUTF(metadata);
                AndroidJNI.CallVoidMethod(_instance, _jmSetMetadata, new jvalue[] { new jvalue()
                                                                                    {
                                                                                        l = arg1
                                                                                    } });
                AndroidJNI.DeleteLocalRef(arg1);
            }
Beispiel #23
0
        public void UpdateDisconnectedDevices()
        {
            var updateDisconnectedMethod = AndroidJNI.GetMethodID(this.bleManagerCls,
                                                                  "updateDisconnected", "()V");
            var getDisconnectedNumMethod = AndroidJNI.GetMethodID(this.bleManagerCls,
                                                                  "getDisconnectedDeviceNum", "()I");
            var getDisconnectedDeviceAddr = AndroidJNI.GetMethodID(this.bleManagerCls,
                                                                   "getDisconnectedDeviceAddr", "(I)Ljava/lang/String;");

            AndroidJNI.CallVoidMethod(this.javaBleManagerObj, updateDisconnectedMethod, null);
            disconnectedDevices.Clear();

            int num = AndroidJNI.CallIntMethod(this.javaBleManagerObj, getDisconnectedNumMethod, null);

            for (int i = 0; i < num; ++i)
            {
                this.argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(i));
                string addr = AndroidJNI.CallStringMethod(this.javaBleManagerObj,
                                                          getDisconnectedDeviceAddr, this.argBuilder.Build());
                this.disconnectedDevices.Add(addr);
            }

            foreach (var addr in disconnectedDevices)
            {
                this.charastericsKeyInfos.Remove(addr);
            }
        }
Beispiel #24
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);
    }
Beispiel #25
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);
    }
Beispiel #26
0
        public void UpdateScannerResult()
        {
            AndroidJNI.PushLocalFrame(32);
            var scanner                   = GetScanner();
            var blitMethod                = AndroidJNI.GetMethodID(this.bleScannerCls, "blit", "()V");
            var getDeviceNumMethod        = AndroidJNI.GetMethodID(this.bleScannerCls, "getDeviceNum", "()I");
            var getDeviceAddrMethod       = AndroidJNI.GetMethodID(this.bleScannerCls, "getDeviceAddr", "(I)Ljava/lang/String;");
            var getDeviceNameByAddrMethod = AndroidJNI.GetMethodID(this.bleScannerCls, "getDeviceNameByAddr", "(Ljava/lang/String;)Ljava/lang/String;");
            var getRssiByAddrMethod       = AndroidJNI.GetMethodID(this.bleScannerCls, "getRssiByAddr", "(Ljava/lang/String;)I");

            AndroidJNI.CallVoidMethod(scanner, blitMethod, null);
            int num = AndroidJNI.CallIntMethod(scanner, getDeviceNumMethod, null);

            scannedDevices.Clear();
            for (int i = 0; i < num; ++i)
            {
                argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(i));
                string addr = AndroidJNI.CallStringMethod(scanner, getDeviceAddrMethod, argBuilder.Build());
                argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(addr));
                string name       = AndroidJNI.CallStringMethod(scanner, getDeviceNameByAddrMethod, argBuilder.Build());
                int    rssi       = AndroidJNI.CallIntMethod(scanner, getRssiByAddrMethod, argBuilder.Build());
                var    scanDevice = new BleScannedDevice(addr, name, rssi);
                this.scannedDevices.Add(scanDevice);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
        }
        /// <summary>
        /// Calls a non-static method with a void return type.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="sig">Sig.</param>
        /// <param name="args">Arguments.</param>
        public void InvokeCallVoid(string name, string sig, params object[] args)
        {
            var method = AndroidJNI.GetMethodID(RawClass, name, sig);

            var jArgs = ConstructArgArray(args);

            AndroidJNI.CallVoidMethod(raw, method, jArgs);
        }
Beispiel #28
0
        /// <summary>
        /// Calls a non-static method with a void return type.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="sig">Sig.</param>
        /// <param name="args">Arguments.</param>
        public void InvokeCallVoid(string name, string sig, params object[] args)
        {
            IntPtr rawClass = AndroidJNI.GetObjectClass(raw);
            IntPtr method   = AndroidJNI.GetMethodID(rawClass, name, sig);

            jvalue[] jArgs = ConstructArgArray(args);
            AndroidJNI.CallVoidMethod(raw, method, jArgs);
        }
Beispiel #29
0
 private void            _UpdateState(int key, byte[] data)
 {
     object[] args = new object[2] {
         key, AndroidJNIHelper.ConvertToJNIArray(data)
     };
     AndroidJNI.CallVoidMethod(android.GetRawObject(), handleSaveStatePtr,
                               AndroidJNIHelper.CreateJNIArgArray(args));
 }
Beispiel #30
0
        public void Disconnect(string addr)
        {
            var disconnectMethod = AndroidJNI.GetMethodID(this.bleManagerCls,
                                                          "disconnect", "(Ljava/lang/String;)V");

            this.argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(addr));
            AndroidJNI.CallVoidMethod(this.javaBleManagerObj,
                                      disconnectMethod, this.argBuilder.Build());
        }