コード例 #1
0
 public static Object newInstanceOf(String className) {
   try {
     Class<?> clazz = Class.forName(className);
     if (clazz != null) {
       return newInstanceOf(clazz);
     }
   } catch (ClassNotFoundException e) {
   }
   return null;
 }
コード例 #2
0
 private void reflectionPluginMethod(String method) {
   WidgetOneApplication app = (WidgetOneApplication) getApplication();
   ThirdPluginMgr tpm = app.getThirdPlugins();
   Map<String, ThirdPluginObject> thirdPlugins = tpm.getPlugins();
   Set<Map.Entry<String, ThirdPluginObject>> pluginSet = thirdPlugins.entrySet();
   for (Map.Entry<String, ThirdPluginObject> entry : pluginSet) {
     try {
       String javaName = entry.getValue().jclass;
       Class c = Class.forName(javaName);
       Method m = c.getMethod(method, new Class[] {Context.class});
       if (null != m) {
         m.invoke(c, new Object[] {this});
       }
     } catch (Exception e) {
     }
   }
 }
コード例 #3
0
ファイル: SDLActivity.java プロジェクト: mactec0/flare-engine
  /** 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;
  }