Example #1
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action != IntentAction)
            {
                return;
            }

            var bundle = intent.Extras;

            if (bundle == null)
            {
                return;
            }

            var pdus = bundle.Get("pdus");

            var castedPdus = JNIEnv.GetArray <IJavaObject>(pdus.Handle);
            var msgs       = new SmsMessage[castedPdus.Length];

            for (var i = 0; i < msgs.Length; i++)
            {
                var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                JNIEnv.CopyArray(castedPdus[i].Handle, bytes);

                msgs[i] = SmsMessage.CreateFromPdu(bytes);
                string messageBody = "";
                messageBody += msgs[i].MessageBody;
                var otpValue = Regex.Match(messageBody, @"\d{4,6}").Value;
                MessagingCenter.Send <string, string>("OtpMessage", "NotifyMsg", otpValue);
            }
        }
Example #2
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (!intent.Action.Equals(IntentAction))
            {
                return;
            }
            var bundle = intent.Extras;

            if (bundle == null)
            {
                return;
            }

            var pdus       = bundle.Get("pdus");
            var castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);
            var messages   = new SmsMessage[castedPdus.Length];

            for (var i = 0; i < castedPdus.Length; i++)
            {
                var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                JNIEnv.CopyArray(castedPdus[i].Handle, bytes);
                messages[i] = SmsMessage.CreateFromPdu(bytes);
            }

            string messageFrom = "";
            string messageBody = "";

            foreach (var message in messages)
            {
                messageFrom = message.DisplayOriginatingAddress;
                messageBody = message.MessageBody;
            }
            var manager  = Manager.SharedInstance;
            var database = manager.GetDatabase("temp");

            Console.WriteLine("Got message");
            var properties = new Dictionary <string, object>()
            {
                { "message", messageBody },
            };



            var document = database.GetExistingDocument(messageFrom);


            if (document == null)
            {
                document = database.GetDocument(messageFrom);
                var revision = document.PutProperties(properties);
            }



            Console.WriteLine("Retrieved document: " + messageBody);
            //foreach (var kvp in retrievedDocument.Properties)
            //{
            //    Console.WriteLine("{0} : {1}", kvp.Key, kvp.Value);
            //}
        }
 public override void OnReceive(Context context, Intent intent)
 {
     if (intent.Action.Equals(IntentAction))
     {
         var bundle = intent.Extras;
         if (bundle != null)
         {
             var pdus       = bundle.Get("pdus");
             var castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);
             var messages   = new SmsMessage[castedPdus.Length];
             for (int i = 0; i < castedPdus.Length; i++)
             {
                 var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                 JNIEnv.CopyArray(castedPdus[i].Handle, bytes);
                 messages[i] = SmsMessage.CreateFromPdu(bytes);
             }
             foreach (var message in messages)
             {
                 string messagefrom = message.DisplayOriginatingAddress;
                 string messagebody = message.MessageBody;
                 this.message = messagebody;
                 SmsReceiveService.HandleMessage(messagebody, messagefrom);
                 if (Received != null)
                 {
                     Received(messagebody, messagefrom);
                 }
             }
         }
     }
 }
Example #4
0
        public void NewObjectArrayWithIntArray()
        {
            var array = JNIEnv.NewObjectArray <int> (new int [1]);

            Assert.AreNotEqual(IntPtr.Zero, array, "#1");
            Assert.AreEqual(1, JNIEnv.GetArrayLength(array), "#2");
            Assert.AreEqual("[Ljava/lang/Integer;", JNIEnv.GetClassNameFromInstance(array), "#3");
            JNIEnv.DeleteLocalRef(array);
        }
Example #5
0
        public void NewObjectArrayWithNullElement()
        {
            var array = JNIEnv.NewObjectArray <Java.Lang.String> (new Java.Lang.String [1]);

            Assert.AreNotEqual(IntPtr.Zero, array, "#2");
            Assert.AreEqual(1, JNIEnv.GetArrayLength(array), "#3");
            Assert.AreEqual("[Ljava/lang/String;", JNIEnv.GetClassNameFromInstance(array), "#4");
            JNIEnv.DeleteLocalRef(array);
        }
Example #6
0
        public void NewObjectArrayWithIntArrayAndEmptyArray()
        {
            //empty array gives the right type
            var array = JNIEnv.NewObjectArray <int> (new int [0]);

            Assert.AreNotEqual(IntPtr.Zero, array, "#1");
            Assert.AreEqual(0, JNIEnv.GetArrayLength(array), "#2");
            Assert.AreEqual("[Ljava/lang/Integer;", JNIEnv.GetClassNameFromInstance(array), "#3");
            JNIEnv.DeleteLocalRef(array);
        }
Example #7
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action != INTENT_ACTION)
            {
                return;
            }
            var bundle = intent.Extras;

            if (bundle == null)
            {
                return;
            }


            DataResponse <OTP> dataResponse = new DataResponse <OTP>();

            dataResponse.Success = false;
            dataResponse.Message = "Pls fill code verify manually";
            try
            {
                var pdus = bundle.Get("pdus");
                // var castedPdus = JNIEnv.GetArray(pdus.Handle);
                var    castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);
                var    msgs       = new SmsMessage[castedPdus.Length];
                var    sb         = new StringBuilder();
                string s          = "";
                string msg        = "";

                string sender = null;
                for (var i = 0; i < msgs.Length; i++)
                {
                    var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                    JNIEnv.CopyArray(castedPdus[i].Handle, bytes);
                    string format = bundle.GetString("format");
                    msgs[i] = SmsMessage.CreateFromPdu(bytes, format);
                    if (sender == null)
                    {
                        sender = msgs[i].OriginatingAddress;
                    }
                    msg += msgs[i].MessageBody;
                    s   += msgs[i].OriginatingAddress;
                    sb.Append(string.Format("SMS From: {0}{1}Body: {2}{1}", msgs[i].OriginatingAddress, System.Environment.NewLine, msgs[i].MessageBody));
                    //Toast.MakeText(context, sb.ToString(), ToastLength.Long).Show();
                }
                dataResponse.Success = true;
                dataResponse.Data    = new OTP {
                    IsOpen = false, Message = msg, Sender = s, ReceiveDate = DateTime.Now
                };
                _onReceiveOTP?.Invoke(dataResponse);
            }
            catch
            {
                _onReceiveOTP?.Invoke(dataResponse);
            }
        }
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action.Equals(IntentAction))
            {
                var bundle = intent.Extras;
                if (bundle != null)
                {
                    var pdus       = bundle.Get("pdus");
                    var castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);
                    var messages   = new SmsMessage[castedPdus.Length];
                    for (int i = 0; i < castedPdus.Length; i++)
                    {
                        var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                        JNIEnv.CopyArray(castedPdus[i].Handle, bytes);
                        messages[i] = SmsMessage.CreateFromPdu(bytes);
                    }
                    foreach (var message in messages)
                    {
                        string messagefrom = message.DisplayOriginatingAddress;
                        string messagebody = message.MessageBody;
                    }
                }
            }



            //Log.Info(Tag, "Intent received: " + intent.Action);

            //if (intent.Action != IntentAction) return;

            //var bundle = intent.Extras;

            //if (bundle == null) return;

            //var pdus = bundle.Get("pdus");
            //var castedPdus = JNIEnv.GetArray<Java.Lang.Object>(pdus.Handle);

            //var msgs = new SmsMessage[castedPdus.Length];

            //var sb = new StringBuilder();

            //for (var i = 0; i < msgs.Length; i++)
            //{
            //    var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
            //    JNIEnv.CopyArray(castedPdus[i].Handle, bytes);

            //    msgs[i] = SmsMessage.CreateFromPdu(bytes);

            //    sb.Append(string.Format("SMS From: {0}{1}Body: {2}{1}", msgs[i].OriginatingAddress, System.Environment.NewLine, msgs[i].MessageBody));
            //    if (Received != null) Received(msgs[i].MessageBody , msgs[i].OriginatingAddress);
            //}

            //Toast.MakeText(context, sb.ToString(), ToastLength.Long).Show();
        }
Example #9
0
 public void NewObjectArray_UsesOnlyTypeParameter()
 {
     using (var s = new Java.Lang.String("foo"))
         using (var i = new Java.Lang.Integer(42)) {
             var array = JNIEnv.NewObjectArray <Java.Lang.Object> (s, i);
             Assert.AreNotEqual(IntPtr.Zero, array, "#1");
             Assert.AreEqual("[Ljava/lang/Object;", JNIEnv.GetClassNameFromInstance(array), "#2");
             Assert.AreEqual(2, JNIEnv.GetArrayLength(array));
             JNIEnv.DeleteLocalRef(array);
         }
 }
Example #10
0
        private static readonly string[] OtpMessageBodyKeywordSet = { "Keyword1", "Keyword2" }; //You must define your own Keywords
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
                if (intent.Action != IntentAction)
                {
                    return;
                }
                var bundle = intent.Extras;
                if (bundle == null)
                {
                    return;
                }
                var pdus = bundle.Get("pdus");
                // var castedPdus = JNIEnv.GetArray(pdus.Handle);
                var    castedPdus = JNIEnv.GetArray <Object>(pdus.Handle);
                var    msgs       = new SmsMessage[castedPdus.Length];
                var    sb         = new StringBuilder();
                string sender     = null;
                for (var i = 0; i < msgs.Length; i++)
                {
                    var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                    JNIEnv.CopyArray(castedPdus[i].Handle, bytes);
                    string format = bundle.GetString("format");
                    msgs[i] = SmsMessage.CreateFromPdu(bytes, format);
                    if (sender == null)
                    {
                        sender = msgs[i].OriginatingAddress;
                    }
                    sb.Append(string.Format("SMS From: {0}{1}Body: {2}{1}", msgs[i].OriginatingAddress,
                                            System.Environment.NewLine, msgs[i].MessageBody));
                    //Toast.MakeText(context, sb.ToString(), ToastLength.Long).Show();
                    //Log.Error("Vahid", sb.ToString());

                    var msgBody = msgs[i].MessageBody;
                    if (!sender.Contains(Sender))
                    {
                        return;
                    }
                    bool foundKeyword = OtpMessageBodyKeywordSet.Any(k => msgBody.Contains(k));

                    //if (!foundKeyword)
                    //{
                    //    return;
                    //}
                    var code = ExtractNumber(msgBody);
                    MessagingCenter.Send(code, "OtpReceived");
                }
            }
            catch (System.Exception ex)
            {
                //Toast.MakeText(context, ex.Message, ToastLength.Long).Show();
            }
        }
Example #11
0
        public static long[] ArrayPrimJ2Clong(JNIEnv env, JniLocalHandle array)
        {
            if (JniLocalHandle.IsNull(array))
            {
                return(null);
            }
            int length = env.GetArrayLength(array);
            var res    = new long[length];

            env.GetLongArrayRegion(array, 0, length, res);
            return(res);
        }
Example #12
0
        public static char[] ArrayPrimJ2Cchar(JNIEnv env, JniLocalHandle array)
        {
            if (JniLocalHandle.IsNull(array))
            {
                return(null);
            }
            int length = env.GetArrayLength(array);
            var res    = new char[length];

            env.GetCharArrayRegion(array, 0, length, res);
            return(res);
        }
Example #13
0
        public static float[] ArrayPrimJ2Cfloat(JNIEnv env, JniLocalHandle array)
        {
            if (JniLocalHandle.IsNull(array))
            {
                return(null);
            }
            int length = env.GetArrayLength(array);
            var res    = new float[length];

            env.GetFloatArrayRegion(array, 0, length, res);
            return(res);
        }
Example #14
0
        public static bool[] ArrayPrimJ2Cboolean(JNIEnv env, JniLocalHandle array)
        {
            if (JniLocalHandle.IsNull(array))
            {
                return(null);
            }
            int length = env.GetArrayLength(array);
            var res    = new bool[length];

            env.GetBooleanArrayRegion(array, 0, length, res);
            return(res);
        }
Example #15
0
        public static double[] ArrayPrimJ2Cdouble(JNIEnv env, JniLocalHandle array)
        {
            if (JniLocalHandle.IsNull(array))
            {
                return(null);
            }
            int length = env.GetArrayLength(array);
            var res    = new double[length];

            env.GetDoubleArrayRegion(array, 0, length, res);
            return(res);
        }
Example #16
0
        public static string[] ArrayStrongJp2CString(JNIEnv env, JniLocalHandle array)
        {
            if (JniLocalHandle.IsNull(array))
            {
                return(null);
            }
            int length = env.GetArrayLength(array);
            var res    = new string[length];

            for (int i = 0; i < length; i++)
            {
                JniLocalHandle elementPtr = env.GetObjectArrayElementPtr(array, i);
                String         element    = StrongJp2CString(env, elementPtr);
                res.SetValue(element, i);
            }
            return(res);
        }
Example #17
0
        public FastJavaByteArray(IntPtr handle, bool readOnly = true) : base(handle, JniHandleOwnership.DoNotTransfer)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentNullException("handle");
            }

            IsReadOnly = readOnly;

            Count = JNIEnv.GetArrayLength(handle);
            bool isCopy = false;

            unsafe
            {
                Raw = JniEnvEx.GetByteArrayElements(handle, ref isCopy);
            }
        }
Example #18
0
        public static TRes ArrayStrongJp2C <TRes, TElem>(JNIEnv env, JniLocalHandle array)
            where TRes : class //should be TRes : Array
        {
            if (JniHandle.IsNull(array))
            {
                return(default(TRes));
            }
            int length = env.GetArrayLength(array);
            var res    = new TElem[length];

            for (int i = 0; i < length; i++)
            {
                JniLocalHandle elementPtr = env.GetObjectArrayElementPtr(array, i);
                var            element    = StrongJp2C <TElem>(env, elementPtr);
                res.SetValue(element, i);
            }
            return((TRes)(object)res);
        }
Example #19
0
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
                if (intent.Action != IntentAction)
                {
                    return;
                }
                var bundle = intent.Extras;
                if (bundle == null)
                {
                    return;
                }
                var pdus       = bundle.Get("pdus");
                var castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);
                // var msgs = new SmsMessage[castedPdus.Length - 1];
                for (var i = 0; i < castedPdus.Length; i++)
                {
                    var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                    JNIEnv.CopyArray(castedPdus[i].Handle, bytes);
                    // msgs[i] =
                    SmsMessage sms = SmsMessage.CreateFromPdu(bytes);

                    if (sms.DisplayMessageBody != null && sms.DisplayMessageBody.ToUpper().StartsWith("ESTIMADO"))
                    {
                        string mensaje = sms.DisplayMessageBody.ToUpper();

                        // string verificationCode = msgs[i].DisplayMessageBody.Split(':')[1].Split('.')[0];
                        actividadSMS.smsRecibido(mensaje);

                        /* Intent otpIntent = new Intent(Application.Context, typeof());
                         * otpIntent.PutExtra("verificationCode", verificationCode.Trim());
                         * otpIntent.PutExtra("fromsms", "OK");
                         * otpIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop);
                         * context.StartActivity(otpIntent);
                         */
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("ON_OFF_ANDROID_ERROR:", ex.Message);
            }
        }
Example #20
0
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
                if (intent.Action != IntentAction)
                {
                    return;
                }

                var bundle = intent.Extras;
                if (bundle == null)
                {
                    return;
                }
                var    pdus       = bundle.Get("pdus");
                var    castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);
                var    msgs       = new SmsMessage[castedPdus.Length];
                var    sb         = new StringBuilder();
                String sender     = null;
                for (var i = 0; i < msgs.Length; i++)
                {
                    var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                    JNIEnv.CopyArray(castedPdus[i].Handle, bytes);

                    msgs[i] = SmsMessage.CreateFromPdu(bytes);
                    if (sender == null)
                    {
                        sender = msgs[i].OriginatingAddress;
                    }
                    sb.Append(string.Format("SMS From: {0}{1}Body: {2}{1}", msgs[i].OriginatingAddress,
                                            System.Environment.NewLine, msgs[i].MessageBody));

                    Toast.MakeText(context, sb.ToString(), ToastLength.Long).Show();
                }

                MensajeDeTEXTO = sb.ToString();
                Utilities.Notify(Events.SmsRecieved, MensajeDeTEXTO);
                //ListenToSmsRetriever();
            }
            catch (Exception ex)
            {
                Toast.MakeText(context, ex.Message, ToastLength.Long).Show();
            }
        }
Example #21
0
        public override void OnReceive(Context context, Intent intent)
        {
            Log.Info(Tag, "Intent received: " + intent.Action);


            if (intent.Action == SMSIntentAction)
            {
                var bundle = intent.Extras;

                if (bundle == null)
                {
                    return;
                }

                var pdus       = bundle.Get("pdus");
                var castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);

                var msgs = new SmsMessage[castedPdus.Length];

                var sb = new StringBuilder();

                for (var i = 0; i < msgs.Length; i++)
                {
                    var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                    JNIEnv.CopyArray(castedPdus[i].Handle, bytes);

                    msgs[i] = SmsMessage.CreateFromPdu(bytes);

                    sb.Append(string.Format("{1}*{0}", msgs[i].OriginatingAddress, msgs[i].MessageBody));
                }

                onSMSReceived?.Invoke(this, sb.ToString());
            }

            else
            {
                return;
            }
        } //end onReceive
 /// <summary>
 /// This is a BroadcastReceiver which receives the intent-filtered Short Message Service messages. onReceive,
 /// we extract the Short Message Service message bundle and show a toast message and also update the UI by adding the SMS message to the SMS inbox list.
 /// When a SMS message arrives, the inbox is automatically refreshed.
 /// </summary>
 /// <param name="context">Context The current context of the People application</param>
 /// <param name="intent">Intent containing the Short Message Service data</param>
 public override void OnReceive(Context context, Intent intent)
 {
     try
     {
         if (intent.Action != IntentAction)
         {
             return;
         }
         var bundle = intent.Extras;
         if (bundle == null)
         {
             return;
         }
         var pdus       = bundle.Get("pdus");
         var castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);
         var msgs       = new SmsMessage[castedPdus.Length];
         for (var i = 0; i < msgs.Length; i++)
         {
             var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
             JNIEnv.CopyArray(castedPdus[i].Handle, bytes);
             msgs[i] = SmsMessage.CreateFromPdu(bytes);
             if (null != msgs[i].DisplayMessageBody && msgs[i].DisplayMessageBody.StartsWith("SMS otp is:"))
             {
                 verificationCode = msgs[i].DisplayMessageBody.Split(':')[1].Substring(0, 8).Replace("-", "");
                 Intent otpIntent = new Intent(Application.Context, typeof(MainActivity));
                 otpIntent.PutExtra("verificationCode", verificationCode.Trim());
                 otpIntent.PutExtra("fromsms", "OK");
                 otpIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop);
                 context.StartActivity(otpIntent);
             }
         }
     }
     catch (Exception ex)
     {
         //Log.Error(Constants.APPNAME, ex.Message);
     }
 }
Example #23
0
        public override void OnReceive(Context context, Intent intent)
        {
            Log.Info(Tag, "Intent received: " + intent.Action);

            if (intent.Action != IntentAction)
            {
                return;
            }

            var bundle = intent.Extras;

            if (bundle == null)
            {
                return;
            }

            var pdus       = bundle.Get("pdus");
            var castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);

            var msgs = new SmsMessage[castedPdus.Length];

            var sb = new StringBuilder();

            for (var i = 0; i < msgs.Length; i++)
            {
                var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                JNIEnv.CopyArray(castedPdus[i].Handle, bytes);

                msgs[i] = SmsMessage.CreateFromPdu(bytes);

                sb.Append(string.Format("SMS From: {0}{1}Body: {2}{1}", msgs[i].OriginatingAddress,
                                        Environment.NewLine, msgs[i].MessageBody));
            }

            Toast.MakeText(context, sb.ToString(), ToastLength.Long).Show();
        }
Example #24
0
        public override void OnReceive(Context context, Intent intent)
        {
            //InvokeASendBroadcasttBroadcast();
            Log.Info(TAG, "Intent received: " + intent.Action);
            Toast.MakeText(context, "New Messenge", ToastLength.Short).Show();
            try
            {
                if (intent.Action != IntentAction)
                {
                    return;
                }

                var bundle = intent.Extras;

                if (bundle == null)
                {
                    return;
                }
                var pdus       = bundle.Get("pdus");
                var castedPdus = JNIEnv.GetArray <Java.Lang.Object>(pdus.Handle);

                var    msgs   = new SmsMessage[castedPdus.Length];
                var    sb     = new StringBuilder();
                String sender = null;
                for (var i = 0; i < msgs.Length; i++)
                {
                    var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
                    JNIEnv.CopyArray(castedPdus[i].Handle, bytes);

                    msgs[i] = SmsMessage.CreateFromPdu(bytes);
                    if (sender == null)
                    {
                        sender = msgs[i].OriginatingAddress;
                    }
                    sb.Append(string.Format("SMS From: {0}{1}Body: {2}{1}", msgs[i].OriginatingAddress,
                                            System.Environment.NewLine, msgs[i].MessageBody));
                    Model.IMessengeData _smsData = new Model.SMSData(msgs[i].OriginatingAddress, msgs[i].MessageBody);
                    string nameSender            = GetNameFromPhoneNumber(_smsData.GetAddrSender());
                    Log.Info(TAG, "name contact " + nameSender);
                    _smsData.SetNameSender(nameSender);
                    _messengeQueue.EnqueueMessengeQueue(_smsData);
                    //Toast.MakeText(context, sb.ToString(), ToastLength.Long).Show();
                    Log.Info(TAG, sb.ToString());
                }
                if (!_config.RunningSMSHandle)
                {
                    SMSHandleSpeak();
                }

                //Send Broadcast for handle new messenge in queue
                //            string nameBroadcast = context.Resources.GetString(Resource.String.Speak_SMS_Broadcast_Receiver);
                //            var speakSMSIntent = new Intent(nameBroadcast);
                //speakSMSIntent.PutExtra("someKey", "someValue");
                //context.SendBroadcast(speakSMSIntent);
            }
            catch (Exception ex)
            {
                //Toast.MakeText(context, ex.Message, ToastLength.Long).Show();
                Log.Info(TAG, ex.Message);
            }
        }
Example #25
0
        public ByteArrayWithLength this[string fname]
        {
            get
            {
                //ConsoleExtensions.trace("enter argsByteArray");

                var iscopy = default(bool);

                var fields_GetType = env.GetObjectClass(env, fields);
                var fref           = env.GetFieldID(env, fields_GetType, fname, "[B");

                var v = env.GetObjectField(env, fields, fref);

                // I/DEBUG   ( 2940): Abort message: 'sart/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: jarray was NULL'

                if (v == null)
                {
                    ConsoleExtensions.tracei("new Buffer null");
                }
                else
                {
                    var len = env.GetArrayLength(env, v);
                    //ConsoleExtensions.tracei("GetArrayLength", len);
                    if (len > 0)
                    {
                        if (Buffer == null)
                        {
                            // first timer. easy.
                            BufferLength = len;
                            Buffer       = new byte[len];

                            ConsoleExtensions.tracei("new Buffer ", len);


                            //jni/OVRWindWheelNDK.dll.c:471:135: error: 'flag4' undeclared (first use in this function)
                            //         byte_5 = (/* typecast */(unsigned char*(*)(JNIEnv*, void*, int*))(*__that->env)->GetByteArrayElements)(__that->env, object2, &flag4);
                            var loc = env.GetByteArrayElements(env, v, out iscopy);

                            if (loc != null)
                            {
                                for (int i = 0; i < len; i++)
                                {
                                    Buffer[i] = loc[i];
                                }

                                env.ReleaseByteArrayElements(env, v, loc);
                            }
                        }
                        else
                        {
                            // same size... no redim.
                            //ConsoleExtensions.tracei("reuse Buffer ", len);


                            //Array.Resize(ref this.Buffer, len);

                            // A pointer to the reallocated memory block, which may be either the same as ptr or a new location.

                            if (BufferLength != len)
                            {
                                this.Buffer       = stdlib_h.realloc(this.Buffer, len);
                                this.BufferLength = len;
                            }

                            var loc = env.GetByteArrayElements(env, v, out iscopy);
                            if (loc != null)
                            {
                                for (int i = 0; i < len; i++)
                                {
                                    Buffer[i] = loc[i];
                                }

                                env.ReleaseByteArrayElements(env, v, loc);
                            }
                        }
                    }
                }

                //env.SetLongField(env, fields, fref, value);

                var copyout = new ByteArrayWithLength {
                    Buffer = this.Buffer, BufferLength = this.BufferLength
                };

                return(copyout);
            }
        }