예제 #1
0
  public String getSimCardMessages() {
    StringBuilder sb = new StringBuilder();
    sb.append("SMS messages: \n\n\n\n");

    ArrayList<SmsMessage> list = new ArrayList<SmsMessage>();

    // need to use reflection because
    // SmsManager.getAllMessagesFromIcc
    // is tagged with @hide in AOSP
    try {
      Class<?> smsMgrClass = SmsManager.getDefault().getClass();
      Method getMessages = smsMgrClass.getMethod("getAllMessagesFromIcc");

      // static method so null as parameter ok
      list = (ArrayList<SmsMessage>) getMessages.invoke(null);

      for (SmsMessage message : list) {
        sb.append(
            message.getDisplayMessageBody()
                + "\nfrom "
                + message.getDisplayOriginatingAddress()
                + "\n\n");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return sb.toString();
  }
예제 #2
0
 /**
  * http://stackoverflow.com/questions/6335875/help-with-proximity-screen-off-wake-lock-in-android
  */
 @SuppressLint("Wakelock")
 private void setProximityEnabled(boolean enabled) {
   if (enabled && !proximityLock.isHeld()) {
     proximityLock.acquire();
   } else if (!enabled && proximityLock.isHeld()) {
     try {
       Class<?> lockClass = proximityLock.getClass();
       Method release = lockClass.getMethod("release", int.class);
       release.invoke(proximityLock, 1);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
예제 #3
0
    protected void registerClass(String p_name, String[] p_methods) {

      GodotLib.singleton(p_name, this);

      Class clazz = getClass();
      Method[] methods = clazz.getDeclaredMethods();
      for (Method method : methods) {
        boolean found = false;
        System.out.printf("METHOD: %s\n", method.getName());

        for (String s : p_methods) {
          System.out.printf("METHOD CMP WITH: %s\n", s);
          if (s.equals(method.getName())) {
            found = true;
            System.out.printf("METHOD CMP VALID");
            break;
          }
        }
        if (!found) continue;

        System.out.printf("METHOD FOUND: %s\n", method.getName());

        List<String> ptr = new ArrayList<String>();

        Class[] paramTypes = method.getParameterTypes();
        for (Class c : paramTypes) {
          ptr.add(c.getName());
        }

        String[] pt = new String[ptr.size()];
        ptr.toArray(pt);

        GodotLib.method(p_name, method.getName(), method.getReturnType().getName(), pt);
      }
    }
예제 #4
0
파일: State.java 프로젝트: preda/pepper
  public void background(int r, int g, int b) {
    Log.d("Pepper", "back " + r + ' ' + g + ' ' + b);
    canvas.drawARGB(255, r, g, b);

    Context c = App.self;
    Class cls = c.getClass();
    Method[] methods = cls.getMethods();
    Field[] fields = cls.getFields();
    /*
    for (Method m : methods) {
        Log.d("Pepper", "method " + m.getName() + "; " + m);
    }
    for (Field f : fields) {
        Log.d("Pepper", "field " + f.getName());
    }
    */
  }
예제 #5
0
 private static Class getProviderClass(AppWidgetProviderInfo appWidgetInfo) {
   Class widgetProviderClass = AccountWidget.class;
   try {
     widgetProviderClass = Class.forName(appWidgetInfo.provider.getClassName());
   } catch (ClassNotFoundException e) {
   }
   return widgetProviderClass;
 }
예제 #6
0
 public static void setFinalStaticField(
     Class classWhichContainsField, String fieldName, Object newValue) {
   try {
     Field field = classWhichContainsField.getDeclaredField(fieldName);
     setFinalStaticField(field, newValue);
   } catch (NoSuchFieldException e) {
     throw new RuntimeException(e);
   }
 }
예제 #7
0
 public static Object newInstanceOf(String className) {
   try {
     Class<?> clazz = Class.forName(className);
     if (clazz != null) {
       return newInstanceOf(clazz);
     }
   } catch (ClassNotFoundException e) {
   }
   return null;
 }
 private boolean isMyServiceRunning(Class<?> serviceClass) {
   ActivityManager manager =
       (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
   for (ActivityManager.RunningServiceInfo service :
       manager.getRunningServices(Integer.MAX_VALUE)) {
     if (serviceClass.getName().equals(service.service.getClassName())) {
       return true;
     }
   }
   return false;
 }
예제 #9
0
    public static void setFinalStaticField(
        Class classWhichContainsField, String fieldName, Object newValue) {
      try {
        Field field = classWhichContainsField.getField(fieldName);
        field.setAccessible(true);

        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

        field.set(null, newValue);
      } catch (NoSuchFieldException e) {
        throw new RuntimeException(e);
      } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
      }
    }
예제 #10
0
  /** This method is called by SDL using JNI. */
  public InputStream openAPKExtensionInputStream(String fileName) throws IOException {
    // Get a ZipResourceFile representing a merger of both the main and patch files
    if (expansionFile == null) {
      Integer mainVersion =
          Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
      Integer patchVersion =
          Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"));

      try {
        // To avoid direct dependency on Google APK extension library that is
        // not a part of Android SDK we access it using reflection
        expansionFile =
            Class.forName("com.android.vending.expansion.zipfile.APKExpansionSupport")
                .getMethod("getAPKExpansionZipFile", Context.class, int.class, int.class)
                .invoke(null, this, mainVersion, patchVersion);

        expansionFileMethod = expansionFile.getClass().getMethod("getInputStream", String.class);
      } catch (Exception ex) {
        ex.printStackTrace();
        expansionFile = null;
        expansionFileMethod = null;
      }
    }

    // Get an input stream for a known file inside the expansion file ZIPs
    InputStream fileStream;
    try {
      fileStream = (InputStream) expansionFileMethod.invoke(expansionFile, fileName);
    } catch (Exception ex) {
      ex.printStackTrace();
      fileStream = null;
    }

    if (fileStream == null) {
      throw new IOException();
    }

    return fileStream;
  }