Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * @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;
 }
Exemple #3
0
  /** @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);
    }
  }