本文整理汇总了C#中CsJni.JniEnvironment类的典型用法代码示例。如果您正苦于以下问题:C# JniEnvironment类的具体用法?C# JniEnvironment怎么用?C# JniEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JniEnvironment类属于CsJni命名空间,在下文中一共展示了JniEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RetrieveAll
public static Dictionary<string, string> RetrieveAll(JniEnvironment environment)
{
Dictionary<string, string> properties = new Dictionary<string,string>();
JniLocalFrame frame = environment.CreateLocalFrame(1);
try
{
JniClass systemClazz = JniClass.FindClass(environment, "java/lang/System");
string[] keyNames = GetJavaPropertyNames(environment, systemClazz);
JniMethod getPropMid = systemClazz.GetStaticMethodId(environment, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
foreach (string keyName in keyNames)
{
JValue[] paramArray = new JValue[1];
paramArray[0].AssignStringValue(environment, keyName);
try
{
string val = getPropMid.CallStaticStringMethod(environment, paramArray);
properties.Add(keyName, val);
}
finally
{
paramArray[0].Free(environment);
}
}
}
finally
{
frame.SafePop();
}
return properties;
}
示例2: CheckException
public static void CheckException(JniEnvironment environment)
{
if (JniThrowable.ExceptionCheck(environment))
{
ThrowCurrentException(environment);
}
}
示例3: Init
internal static void Init(JniEnvironment environment)
{
if (JavaVM.IsLogTypeEnabled(JavaVMLogTypes.RedirectStdOut | JavaVMLogTypes.RedirectStdErr))
{
JniLocalFrame frame = environment.CreateLocalFrame(1);
try
{
JniClass peer = JavaNativeMethodRegistrar.RegisterCounterpartAndReturnPeer(environment,
typeof(JavaStdStreamRedirector));
if (JavaVM.IsLogTypeEnabled(JavaVMLogTypes.RedirectStdOut))
{
HookStream(environment, peer, JavaVMLogTypes.RedirectStdOut, "redirectStdOut");
}
if (JavaVM.IsLogTypeEnabled(JavaVMLogTypes.RedirectStdErr))
{
HookStream(environment, peer, JavaVMLogTypes.RedirectStdErr, "redirectStdErr");
}
}
finally
{
frame.SafePop();
}
}
}
示例4: JniThreadMonitor
internal JniThreadMonitor(JniEnvironment env, JniObject objectHandle)
{
JniObject.VerifyInputJniObject(objectHandle);
mEnvironment = env;
mObjectHandle = objectHandle;
Enter();
}
示例5: LogBannerProperties
public static void LogBannerProperties(JniEnvironment environment)
{
Dictionary<string, string> properties = RetrieveAll(environment);
JavaVM.Log("Current Java System Properties");
string[] logPropNames = {
"java.version",
"java.vendor",
"java.home",
"java.vm.version",
"java.vm.vendor",
"java.vm.name",
"java.class.version",
"java.class.path",
"java.library.path",
"os.name",
"os.arch",
"os.version",
"user.name",
};
foreach (string logPropName in logPropNames)
{
JavaVM.Log(logPropName + " = " + properties[logPropName]);
}
}
示例6: ExtractStringFromHandle
public static string ExtractStringFromHandle(JniEnvironment environment, IntPtr handle)
{
VerifyEnvironment(environment);
unsafe
{
int length = GetStringLengthCore(environment, handle);
char* p = JniEnvironment.Functions.GetStringCritical(environment.Handle, handle, null);
if (p == null)
{
JniThrowable.ThrowCurrentException(environment);
}
try
{
// IMPORTANT - do not change code between GetStringCritical/ReleaseStringCritical.
// See JNI documentation.
return new String(p, 0, length);
}
finally
{
JniEnvironment.Functions.ReleaseStringCritical(environment.Handle, handle, p);
// EXCEPTION CHECK: Do nothing, this method safe to call while exception is pending, does
// not raise additional exceptions.
}
}
}
示例7: ExceptionCheck
public static bool ExceptionCheck(JniEnvironment environment)
{
byte result = JniEnvironment.Functions.ExceptionCheck(environment.Handle);
// EXCEPTION CHECK: Do nothing, this method safe to call while exception is pending, does
// not raise additional exceptions.
return JBooleanConverter.From(result);
}
示例8: HookStream
private static void HookStream(JniEnvironment environment, JniClass nativeClazz,
JavaVMLogTypes hook, string javaHookMethod)
{
JniMethod outMid = nativeClazz.GetStaticMethodId(environment, javaHookMethod, "(I)V");
JValue[] paramArray = new JValue[1];
paramArray[0].AssignIntValue((int)hook);
outMid.CallStaticVoidMethod(environment, paramArray);
}
示例9: PackLongArray
public static JniLongArray PackLongArray(JniEnvironment environment, long[] sourceArray)
{
VerifyEnvironment(environment);
if (sourceArray == null) { return null; }
JniLongArray arrayHandle = NewLongArray(environment, sourceArray.Length);
if (sourceArray.Length > 0)
{
arrayHandle.PackPrimitiveArray<long>(environment, sourceArray);
}
return arrayHandle;
}
示例10: PackIntArray
public static JniIntArray PackIntArray(JniEnvironment environment, int[] sourceArray)
{
VerifyEnvironment(environment);
if (sourceArray == null) { return null; }
JniIntArray arrayHandle = NewIntArray(environment, sourceArray.Length);
if (sourceArray.Length > 0)
{
arrayHandle.PackPrimitiveArray<int>(environment, sourceArray);
}
return arrayHandle;
}
示例11: PackCharArray
public static JniCharArray PackCharArray(JniEnvironment environment, char[] sourceArray)
{
VerifyEnvironment(environment);
if (sourceArray == null) { return null; }
JniCharArray arrayHandle = NewCharArray(environment, sourceArray.Length);
if (sourceArray.Length > 0)
{
arrayHandle.PackPrimitiveArray<char>(environment, sourceArray);
}
return arrayHandle;
}
示例12: PackByteArray
public static JniByteArray PackByteArray(JniEnvironment environment, byte[] sourceArray)
{
VerifyEnvironment(environment);
if (sourceArray == null) { return null; }
JniByteArray arrayHandle = NewByteArray(environment, sourceArray.Length);
if (sourceArray.Length > 0)
{
arrayHandle.PackPrimitiveArray<byte>(environment, sourceArray);
}
return arrayHandle;
}
示例13: JniClass
internal JniClass(JniEnvironment environment, IntPtr handle, JniObjectLifecycle lifecycle)
: base(environment, handle, lifecycle)
{
// TODO - make this instance global???
if (!mStaticsInitialized)
{
mStaticsInitialized = true;
JniClass localClassClass = this.GetObjectClass(environment);
// NOTE: no need to NewGlobalRef class handle for java.lang.Class, will not be unloaded
mGetNameMid = localClassClass.GetMethodId(environment, "getName", "()Ljava/lang/String;");
}
}
示例14: NewObjectCore
public JniObject NewObjectCore(JniEnvironment environment, JValue[] arguments, JniConcreteObjectType concreteType)
{
VerifyEnvironment(environment);
// NOTE: OK if "JValue[] arguments" is null
IntPtr result = JniEnvironment.Functions.NewObjectA(environment.Handle, this.DeclaringClass.Handle, this.Handle, arguments);
if (IntPtr.Zero == result)
{
JniThrowable.ThrowCurrentException(environment); // null result means an exception occurred
}
// EXCEPTION CHECK: Do nothing, already checked for exception above.
return JniObject.CreateObjectOfType(environment, result, concreteType);
}
示例15: GetDoubleField
public double GetDoubleField(
JniEnvironment environment,
JniObject jniObject)
{
VerifyReturnType(JniType.Double);
VerifyEnvironment(environment);
VerifyNotStatic();
VerifyInputJniObject(jniObject);
double result = JniEnvironment.Functions.GetDoubleField(environment.Handle, jniObject.Handle, this.Handle);
JniThrowable.CheckException(environment);
return result;
}