NewStringUTF() public static method

public static NewStringUTF ( string bytes ) : IntPtr
bytes string
return System.IntPtr
Exemplo n.º 1
0
 public static IntPtr GetConstructorMember(IntPtr jclass, string signature)
 {
     jvalue[] args = new jvalue[2];
     try
     {
         args[0].l = jclass;
         args[1].l = AndroidJNISafe.NewStringUTF(signature);
         return(AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetConstructorID, args));
     }
     finally
     {
         AndroidJNISafe.DeleteLocalRef(args[1].l);
     }
 }
Exemplo n.º 2
0
 public static IntPtr GetFieldMember(IntPtr jclass, string fieldName, string signature, bool isStatic)
 {
     jvalue[] args = new jvalue[4];
     try
     {
         args[0].l = jclass;
         args[1].l = AndroidJNISafe.NewStringUTF(fieldName);
         args[2].l = AndroidJNISafe.NewStringUTF(signature);
         args[3].z = isStatic;
         return(AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetFieldID, args));
     }
     finally
     {
         AndroidJNISafe.DeleteLocalRef(args[1].l);
         AndroidJNISafe.DeleteLocalRef(args[2].l);
     }
 }
Exemplo n.º 3
0
 public static IntPtr GetMethodMember(IntPtr jclass, string methodName, string signature, bool isStatic)
 {
     jvalue[] array = new jvalue[4];
     try
     {
         array[0].l = jclass;
         array[1].l = AndroidJNISafe.NewStringUTF(methodName);
         array[2].l = AndroidJNISafe.NewStringUTF(signature);
         array[3].z = isStatic;
         return(AndroidJNISafe.CallStaticObjectMethod(s_ReflectionHelperClass, s_ReflectionHelperGetMethodID, array));
     }
     finally
     {
         AndroidJNISafe.DeleteLocalRef(array[1].l);
         AndroidJNISafe.DeleteLocalRef(array[2].l);
     }
 }
Exemplo n.º 4
0
        public static jvalue[] CreateJNIArgArray(object[] args)
        {
            jvalue[] array = new jvalue[args.GetLength(0)];
            int      num   = 0;

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

            if (AndroidReflection.IsPrimitive(elementType))
            {
                if (elementType == typeof(int))
                {
                    return(AndroidJNISafe.ToIntArray((int[])array));
                }
                if (elementType == typeof(bool))
                {
                    return(AndroidJNISafe.ToBooleanArray((bool[])array));
                }
                if (elementType == typeof(byte))
                {
                    return(AndroidJNISafe.ToByteArray((byte[])array));
                }
                if (elementType == typeof(short))
                {
                    return(AndroidJNISafe.ToShortArray((short[])array));
                }
                if (elementType == typeof(long))
                {
                    return(AndroidJNISafe.ToLongArray((long[])array));
                }
                if (elementType == typeof(float))
                {
                    return(AndroidJNISafe.ToFloatArray((float[])array));
                }
                if (elementType == typeof(double))
                {
                    return(AndroidJNISafe.ToDoubleArray((double[])array));
                }
                if (elementType == typeof(char))
                {
                    return(AndroidJNISafe.ToCharArray((char[])array));
                }
                return(IntPtr.Zero);
            }
            if (elementType == typeof(string))
            {
                string[] array2  = (string[])array;
                int      length  = array.GetLength(0);
                IntPtr   intPtr  = AndroidJNISafe.FindClass("java/lang/String");
                IntPtr   intPtr2 = AndroidJNI.NewObjectArray(length, intPtr, IntPtr.Zero);
                for (int i = 0; i < length; i++)
                {
                    IntPtr intPtr3 = AndroidJNISafe.NewStringUTF(array2[i]);
                    AndroidJNI.SetObjectArrayElement(intPtr2, i, intPtr3);
                    AndroidJNISafe.DeleteLocalRef(intPtr3);
                }
                AndroidJNISafe.DeleteLocalRef(intPtr);
                return(intPtr2);
            }
            if (elementType == typeof(AndroidJavaObject))
            {
                AndroidJavaObject[] array3 = (AndroidJavaObject[])array;
                int      length2           = array.GetLength(0);
                IntPtr[] array4            = new IntPtr[length2];
                IntPtr   intPtr4           = AndroidJNISafe.FindClass("java/lang/Object");
                IntPtr   intPtr5           = IntPtr.Zero;
                for (int j = 0; j < length2; j++)
                {
                    if (array3[j] != null)
                    {
                        array4[j] = array3[j].GetRawObject();
                        IntPtr rawClass = array3[j].GetRawClass();
                        if (intPtr5 != rawClass)
                        {
                            intPtr5 = ((!(intPtr5 == IntPtr.Zero)) ? intPtr4 : rawClass);
                        }
                    }
                    else
                    {
                        array4[j] = IntPtr.Zero;
                    }
                }
                IntPtr result = AndroidJNISafe.ToObjectArray(array4, intPtr5);
                AndroidJNISafe.DeleteLocalRef(intPtr4);
                return(result);
            }
            throw new Exception("JNI; Unknown array type '" + elementType + "'");
        }
Exemplo n.º 6
0
        public static IntPtr ConvertToJNIArray(Array array)
        {
            Type elementType = array.GetType().GetElementType();

            if (AndroidReflection.IsPrimitive(elementType))
            {
                if (elementType == typeof(int))
                {
                    return(AndroidJNISafe.ToIntArray((int[])array));
                }
                if (elementType == typeof(bool))
                {
                    return(AndroidJNISafe.ToBooleanArray((bool[])array));
                }
                if (elementType == typeof(byte))
                {
                    return(AndroidJNISafe.ToByteArray((byte[])array));
                }
                if (elementType == typeof(short))
                {
                    return(AndroidJNISafe.ToShortArray((short[])array));
                }
                if (elementType == typeof(long))
                {
                    return(AndroidJNISafe.ToLongArray((long[])array));
                }
                if (elementType == typeof(float))
                {
                    return(AndroidJNISafe.ToFloatArray((float[])array));
                }
                if (elementType == typeof(double))
                {
                    return(AndroidJNISafe.ToDoubleArray((double[])array));
                }
                if (elementType != typeof(char))
                {
                    return(IntPtr.Zero);
                }
                return(AndroidJNISafe.ToCharArray((char[])array));
            }
            if (elementType == typeof(string))
            {
                string[] strArray = (string[])array;
                int      size     = array.GetLength(0);
                IntPtr   clazz    = AndroidJNISafe.FindClass("java/lang/String");
                IntPtr   ptr2     = AndroidJNI.NewObjectArray(size, clazz, IntPtr.Zero);
                for (int j = 0; j < size; j++)
                {
                    IntPtr ptr3 = AndroidJNISafe.NewStringUTF(strArray[j]);
                    AndroidJNI.SetObjectArrayElement(ptr2, j, ptr3);
                    AndroidJNISafe.DeleteLocalRef(ptr3);
                }
                AndroidJNISafe.DeleteLocalRef(clazz);
                return(ptr2);
            }
            if (elementType != typeof(AndroidJavaObject))
            {
                throw new Exception("JNI; Unknown array type '" + elementType + "'");
            }
            AndroidJavaObject[] objArray = (AndroidJavaObject[])array;
            int length = array.GetLength(0);

            IntPtr[] ptrArray = new IntPtr[length];
            IntPtr   localref = AndroidJNISafe.FindClass("java/lang/Object");
            IntPtr   zero     = IntPtr.Zero;

            for (int i = 0; i < length; i++)
            {
                if (objArray[i] != null)
                {
                    ptrArray[i] = objArray[i].GetRawObject();
                    IntPtr rawClass = objArray[i].GetRawClass();
                    if (zero != rawClass)
                    {
                        if (zero == IntPtr.Zero)
                        {
                            zero = rawClass;
                        }
                        else
                        {
                            zero = localref;
                        }
                    }
                }
                else
                {
                    ptrArray[i] = IntPtr.Zero;
                }
            }
            IntPtr ptr7 = AndroidJNISafe.ToObjectArray(ptrArray, zero);

            AndroidJNISafe.DeleteLocalRef(localref);
            return(ptr7);
        }
Exemplo n.º 7
0
        public static IntPtr ConvertToJNIArray(Array array)
        {
            System.Type elementType = array.GetType().GetElementType();
            if (AndroidReflection.IsPrimitive(elementType))
            {
                if (elementType == typeof(int))
                {
                    return(AndroidJNISafe.ToIntArray((int[])array));
                }
                if (elementType == typeof(bool))
                {
                    return(AndroidJNISafe.ToBooleanArray((bool[])array));
                }
                if (elementType == typeof(byte))
                {
                    return(AndroidJNISafe.ToByteArray((byte[])array));
                }
                if (elementType == typeof(short))
                {
                    return(AndroidJNISafe.ToShortArray((short[])array));
                }
                if (elementType == typeof(long))
                {
                    return(AndroidJNISafe.ToLongArray((long[])array));
                }
                if (elementType == typeof(float))
                {
                    return(AndroidJNISafe.ToFloatArray((float[])array));
                }
                if (elementType == typeof(double))
                {
                    return(AndroidJNISafe.ToDoubleArray((double[])array));
                }
                if (elementType == typeof(char))
                {
                    return(AndroidJNISafe.ToCharArray((char[])array));
                }
                return(IntPtr.Zero);
            }
            if (elementType == typeof(string))
            {
                string[] strArray = (string[])array;
                int      length   = array.GetLength(0);
                IntPtr   num      = AndroidJNISafe.FindClass("java/lang/String");
                IntPtr   array1   = AndroidJNI.NewObjectArray(length, num, IntPtr.Zero);
                for (int index = 0; index < length; ++index)
                {
                    IntPtr localref = AndroidJNISafe.NewStringUTF(strArray[index]);
                    AndroidJNI.SetObjectArrayElement(array1, index, localref);
                    AndroidJNISafe.DeleteLocalRef(localref);
                }
                AndroidJNISafe.DeleteLocalRef(num);
                return(array1);
            }
            if (elementType != typeof(AndroidJavaObject))
            {
                throw new Exception("JNI; Unknown array type '" + (object)elementType + "'");
            }
            AndroidJavaObject[] androidJavaObjectArray = (AndroidJavaObject[])array;
            int length1 = array.GetLength(0);

            IntPtr[] array2    = new IntPtr[length1];
            IntPtr   localref1 = AndroidJNISafe.FindClass("java/lang/Object");
            IntPtr   type      = IntPtr.Zero;

            for (int index = 0; index < length1; ++index)
            {
                if (androidJavaObjectArray[index] != null)
                {
                    array2[index] = androidJavaObjectArray[index].GetRawObject();
                    IntPtr rawClass = androidJavaObjectArray[index].GetRawClass();
                    if (type != rawClass)
                    {
                        type = !(type == IntPtr.Zero) ? localref1 : rawClass;
                    }
                }
                else
                {
                    array2[index] = IntPtr.Zero;
                }
            }
            IntPtr objectArray = AndroidJNISafe.ToObjectArray(array2, type);

            AndroidJNISafe.DeleteLocalRef(localref1);
            return(objectArray);
        }