示例#1
0
 Class<?> getPluginClass(String packageName, String className)
     throws NameNotFoundException, ClassNotFoundException {
   Context pluginContext =
       this.mAppContext.createPackageContext(
           packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
   ClassLoader pluginCL = pluginContext.getClassLoader();
   return pluginCL.loadClass(className);
 }
示例#2
0
文件: Util.java 项目: gubo/slipwire
 /**
  * @param context
  * @return
  */
 public static String version(final Context context) {
   String version = null;
   try {
     final PackageInfo packageinfo =
         context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
     version = packageinfo.versionName;
   } catch (Exception x) {
     DBG.m(x);
   }
   return version;
 }
示例#3
0
文件: Util.java 项目: gubo/slipwire
 /**
  * @param context
  * @return
  */
 public static String getApplicationName(final Context context) {
   String name = null;
   try {
     final PackageManager packagemanager = context.getPackageManager();
     final PackageInfo packageinfo = packagemanager.getPackageInfo(context.getPackageName(), 0);
     name =
         packageinfo.applicationInfo.loadLabel(packagemanager).toString()
             + "("
             + packageinfo.packageName
             + ")";
   } catch (Exception x) {
     DBG.m(x);
   }
   return name;
 }
示例#4
0
文件: Util.java 项目: gubo/slipwire
 /**
  * http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html
  * http://developer.android.com/training/basics/network-ops/managing.html
  *
  * @param context
  * @return
  */
 public static boolean isNetworkAvailable(final Context context, final boolean mobile) {
   boolean available = false;
   try {
     final ConnectivityManager connectivitymanager =
         (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     final NetworkInfo networkinfo = connectivitymanager.getActiveNetworkInfo();
     if ((networkinfo != null) && networkinfo.isConnectedOrConnecting()) {
       switch (networkinfo.getType()) {
         case ConnectivityManager.TYPE_WIFI:
         case ConnectivityManager.TYPE_WIMAX:
         case ConnectivityManager.TYPE_ETHERNET:
           available = true;
           break;
         case ConnectivityManager.TYPE_MOBILE:
           if (mobile) {
             available = true;
           }
           break;
       }
     }
   } catch (Throwable x) {
     DBG.m(x);
   }
   return available;
 }
示例#5
0
文件: Util.java 项目: gubo/slipwire
 /**
  * @param context
  * @param classname
  * @return
  */
 public static boolean isServiceRunning(final Context context, final String classname) {
   boolean running = false;
   try {
     final ActivityManager activitymanager =
         (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
     final List<ActivityManager.RunningServiceInfo> runningserviceinfos =
         activitymanager.getRunningServices(Integer.MAX_VALUE);
     for (final ActivityManager.RunningServiceInfo runningserviceinfo : runningserviceinfos) {
       final String serviceclassname = runningserviceinfo.service.getClassName();
       if (serviceclassname == null) {
         continue;
       }
       if (serviceclassname.equals(classname)) {
         running = true;
         break;
       }
     }
   } catch (Exception x) {
     DBG.m(x);
   }
   return running;
 }
示例#6
0
文件: Util.java 项目: gubo/slipwire
  /** @param context */
  public static void showDiagnosticInfo(final Context context) {
    try {
      DBG.m("  Build.VERSION.SDK_INT: " + Build.VERSION.SDK_INT);
      DBG.m("  Build.VERSION.CODENAME: " + Build.VERSION.CODENAME);
      DBG.m("  Build.DEVICE: " + android.os.Build.DEVICE);
      DBG.m("  Build.MODEL: " + android.os.Build.MODEL);
      DBG.m("  Build.PRODUCT: " + android.os.Build.PRODUCT);

      final DisplayMetrics displaymetrics = new DisplayMetrics();
      final WindowManager windowmanager =
          (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
      windowmanager.getDefaultDisplay().getMetrics(displaymetrics);
      DBG.m("  DisplayMetrics.density: " + displaymetrics.density);
      DBG.m("  DisplayMetrics.densityDpi: " + displaymetrics.densityDpi);
      DBG.m("  DisplayMetrics.heightPixels: " + displaymetrics.heightPixels);
      DBG.m("  DisplayMetrics.widthPixels: " + displaymetrics.widthPixels);
      DBG.m("  DisplayMetrics.scaledDensity: " + displaymetrics.scaledDensity);
      DBG.m("  DisplayMetrics.xdpi: " + displaymetrics.xdpi);
      DBG.m("  DisplayMetrics.ydpi: " + displaymetrics.ydpi);
    } catch (Exception x) {
      DBG.m(x);
    }
  }