Exemplo n.º 1
0
 /// <summary>
 /// 以反射方式,尝试通过Application读取数据
 /// </summary>
 /// <param name="pathUri"></param>
 /// <returns></returns>
 public static System.IO.Stream ApplicationResourceStream(Uri pathUri)
 {
     if (!supportApplication)
     {
         return(null);
     }
     try
     {
         if (appType == null)
         {
             try
             {
                 appType            = JavaRuntime.ClassforName("System.Windows.Application");
                 supportApplication = true;
             }
             catch
             {
                 supportApplication = false;
             }
         }
         object o = JavaRuntime.NewInstance(appType);
         System.Reflection.MethodInfo method = JavaRuntime.GetMethod(appType, "GetResourceStream", pathUri.GetType());
         object res = JavaRuntime.Invoke(method, o, pathUri);
         if (res != null)
         {
             System.Reflection.MethodInfo info = res.GetType().GetMethod("get_Stream");
             object open = JavaRuntime.Invoke(info, res);
             return(open as System.IO.Stream);
         }
     }
     catch
     {
     }
     return(null);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 加载并显示Screen到设备屏幕
 /// </summary>
 public void ShowScreen()
 {
     if (setupSensors)
     {
         Type accelerometer = null;
         if (accelerometer == null)
         {
             try
             {
                 accelerometer  = JavaRuntime.ClassforName("Loon.Core.Input.Sensors.AccelerometerExecute");
                 supportSensors = true;
             }
             catch (Exception)
             {
                 supportSensors = false;
             }
         }
         if (supportSensors)
         {
             try
             {
                 object o = JavaRuntime.NewInstance(accelerometer);
                 System.Reflection.MethodInfo initialize = JavaRuntime.GetMethod(accelerometer, "Initialize");
                 initialize.Invoke(o, null);
                 System.Reflection.MethodInfo isActive = JavaRuntime.GetMethod(accelerometer, "IsActive");
                 supportSensors = (bool)isActive.Invoke(o, null);
             }
             catch (Exception)
             {
                 supportSensors = false;
             }
         }
     }
 }