Пример #1
0
  /**
   * Check for valid Log Files. Log.out is continously written Log.out.1 Log.out.2 ... Log.out.n
   * will be created in worst case else Log.out.1 will be transferred successfully After Successful
   * transfer, delete all files except Log.out
   *
   * @param String filename - filename
   * @return boolean
   */
  private void renameLogFiles() {
    Log.i("PhoneLab-" + getClass().getSimpleName(), "Starting to rename files");
    File[] allFiles = new File(LOG_DIR).listFiles();
    Log.i("PhoneLab-" + getClass().getSimpleName(), "Files found .. " + allFiles.length);
    if (allFiles.length > 1) {
      for (int i = 0; i < allFiles.length; i++) {
        String fileName = allFiles[i].getName();
        if (fileName != "log.out" && fileName.startsWith("log.out.")) {
          Log.i(
              "PhoneLab-" + getClass().getSimpleName(), "File " + i + " " + allFiles[i].getName());
          if (allFiles[i].renameTo(new File(LOG_DIR + System.currentTimeMillis() + ".log"))) {
            Log.i("PhoneLab-" + getClass().getSimpleName(), "Renamed successfully");
          } else {
            Log.w("PhoneLab-" + getClass().getSimpleName(), "Renamed failed");
          }
        }
      }
    } else { // No File
      Log.i("PhoneLab-" + getClass().getSimpleName(), "No Log file exist");
    }

    ConnectivityManager myConnManager =
        (ConnectivityManager)
            getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (myConnManager != null) {
      if (myConnManager.getActiveNetworkInfo() != null) {
        if (myConnManager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
            || myConnManager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_MOBILE) {
          isFailed = false;
        } else {
          isFailed = true;
        }
      }
    }
  }
Пример #2
0
  /*
  isInternetOn() checks the Internet connection and displays an AlertDialog when the device is not connected to Internet
  and get a page of items when the device is connected to the Internet.
   */
  public final void isInternetOn() {

    // get Connectivity Manager object to check connection
    ConnectivityManager connectivitymanager =
        (ConnectivityManager) getSystemService(getBaseContext().CONNECTIVITY_SERVICE);

    // Check for network connections
    if (connectivitymanager.getActiveNetworkInfo() != null
        && connectivitymanager.getActiveNetworkInfo().isConnected()) {

      // if connected with internet

      adapter = new ProductAdapter(this, R.layout.itemview, arrayList);
      getpage();
      grdview.setAdapter(adapter);

    } else {

      new AlertDialog.Builder(this)
          .setTitle("Connection Error")
          .setMessage("Please check your Internet connection.")
          .setNegativeButton(
              android.R.string.no,
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                  isInternetOn();
                }
              })
          .setIcon(android.R.drawable.ic_dialog_alert)
          .show();
    }
  }
Пример #3
0
  @Override
  public void onReceive(Context context, Intent intent) {
    // make sure sd card is ready, if not don't try to send
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
      return;
    }

    String action = intent.getAction();
    ConnectivityManager manager =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo currentNetworkInfo = manager.getActiveNetworkInfo();

    if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
      if (currentNetworkInfo != null
          && currentNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
        if (interfaceIsEnabled(context, currentNetworkInfo)) {
          uploadForms(context);
        }
      }
    } else if (action.equals("com.geoodk.collect.android.FormSaved")) {
      ConnectivityManager connectivityManager =
          (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo ni = connectivityManager.getActiveNetworkInfo();

      if (ni == null || !ni.isConnected()) {
        // not connected, do nothing
      } else {
        if (interfaceIsEnabled(context, ni)) {
          uploadForms(context);
        }
      }
    }
  }
  public void uploadToServer() {
    Log.d(TAG, "Connecting to " + stringUrl);
    try {
      ConnectivityManager connMgr =
          (ConnectivityManager) mSoftKeyboard.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
      if (networkInfo != null && networkInfo.isConnected()) {
        Log.d(TAG, networkInfo.getTypeName());
        Log.d(TAG, networkInfo.getSubtypeName());
        Log.d(TAG, networkInfo.toString());
        Log.d(TAG, "Apparently nw is available");
        new SendStatsTask().execute(stringUrl);
      } else {
        Log.d(TAG, "No network connection available.");
        connMgr.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);
        if (connMgr.getActiveNetworkInfo().isConnected()) {
          Log.d(TAG, "Using mobile data");
          new SendStatsTask().execute(stringUrl);
        }
        Log.d(TAG, "No go for mobile data either");
      }

    } catch (Exception e) {
      Log.d(TAG, e.getMessage());
    }
    // if successful delete local data

  }
Пример #5
0
  public static boolean isOnline(Context context) {
    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    return (cm.getActiveNetworkInfo() != null
            && cm.getActiveNetworkInfo().isConnectedOrConnecting())
        && !isAirplaneModeOn(context);
  }
Пример #6
0
 @Override
 public boolean isNetworkActive() {
   ConnectivityManager cm =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   return (cm.getActiveNetworkInfo() != null
       && cm.getActiveNetworkInfo().isAvailable()
       && cm.getActiveNetworkInfo().isConnected());
 }
  private boolean isOnline() {
    // TODO Auto-generated method stub
    ConnectivityManager cm =
        (ConnectivityManager)
            getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);

    return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting();
  }
Пример #8
0
 private boolean checkInternetConnection() {
   ConnectivityManager conMgr =
       (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
   // ARE WE CONNECTED TO THE NET
   return conMgr.getActiveNetworkInfo() != null
       && conMgr.getActiveNetworkInfo().isAvailable()
       && conMgr.getActiveNetworkInfo().isConnected();
 }
Пример #9
0
 public boolean isConnected() {
   ConnectivityManager connectivity =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivity.getActiveNetworkInfo() != null) {
     if (connectivity.getActiveNetworkInfo().isConnected()) return true;
   }
   return false;
 }
Пример #10
0
  public static boolean isOnline(Context context) {
    ConnectivityManager mConMgr =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    return mConMgr.getActiveNetworkInfo() != null
        && mConMgr.getActiveNetworkInfo().isAvailable()
        && mConMgr.getActiveNetworkInfo().isConnected();
  }
Пример #11
0
 /**
  * wifi是否打开.
  *
  * @param context the context
  * @return true, if is wifi enabled
  */
 public static boolean isWifiEnabled(Context context) {
   ConnectivityManager mgrConn =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   TelephonyManager mgrTel =
       (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
   return ((mgrConn.getActiveNetworkInfo() != null
           && mgrConn.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED)
       || mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
 }
 public ec(Context context) {
   boolean z = true;
   AudioManager audioManager = (AudioManager) context.getSystemService("audio");
   ConnectivityManager connectivityManager =
       (ConnectivityManager) context.getSystemService("connectivity");
   DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
   Locale locale = Locale.getDefault();
   PackageManager packageManager = context.getPackageManager();
   TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
   Intent registerReceiver =
       context.registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
   this.rb = audioManager.getMode();
   this.rc = m947a(packageManager, "geo:0,0?q=donuts") != null;
   this.rd = m947a(packageManager, "http://www.google.com") != null;
   this.re = telephonyManager.getNetworkOperator();
   this.rf = locale.getCountry();
   this.rg = et.bV();
   this.rh = audioManager.isMusicActive();
   this.ri = audioManager.isSpeakerphoneOn();
   this.rj = locale.getLanguage();
   this.rk = m948a(packageManager);
   this.rl = audioManager.getStreamVolume(3);
   this.rm = m946a(context, connectivityManager, packageManager);
   this.rn = telephonyManager.getNetworkType();
   this.ro = telephonyManager.getPhoneType();
   this.rp = audioManager.getRingerMode();
   this.rq = audioManager.getStreamVolume(2);
   this.rr = displayMetrics.density;
   this.rs = displayMetrics.widthPixels;
   this.rt = displayMetrics.heightPixels;
   if (registerReceiver != null) {
     int intExtra = registerReceiver.getIntExtra(NotificationCompatApi21.CATEGORY_STATUS, -1);
     this.ru =
         (double)
             (((float) registerReceiver.getIntExtra("level", -1))
                 / ((float) registerReceiver.getIntExtra("scale", -1)));
     if (!(intExtra == 2 || intExtra == 5)) {
       z = false;
     }
     this.rv = z;
   } else {
     this.ru = -1.0d;
     this.rv = false;
   }
   if (VERSION.SDK_INT >= 16) {
     this.rw = connectivityManager.isActiveNetworkMetered();
     if (connectivityManager.getActiveNetworkInfo() != null) {
       this.rx = connectivityManager.getActiveNetworkInfo().getDetailedState().ordinal();
       return;
     } else {
       this.rx = -1;
       return;
     }
   }
   this.rw = false;
   this.rx = -1;
 }
Пример #13
0
  public final boolean isInternetAvailable() {
    // check if we are connected to the internet
    ConnectivityManager connectivityManager =
        (ConnectivityManager) mContext.getSystemService(mContext.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectivityManager.getActiveNetworkInfo();
    if (info == null) return false;

    return connectivityManager.getActiveNetworkInfo().isConnected();
  }
Пример #14
0
  public static void restartServices(Context context) {
    stopServices(context);

    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
      startServices(context);
    }
  }
 /**
  * 判断网络连接是否已开
  *
  * @param context
  * @return true 已打开 false 未打开
  */
 public static boolean isConn(Context context) {
   boolean bisConnFlag = false;
   ConnectivityManager conManager =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo network = conManager.getActiveNetworkInfo();
   if (network != null) {
     bisConnFlag = conManager.getActiveNetworkInfo().isAvailable();
   }
   return bisConnFlag;
 }
Пример #16
0
  public static boolean isOnline() {
    ConnectivityManager cm =
        (ConnectivityManager) sContext.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (cm.getActiveNetworkInfo() != null) {
      return cm.getActiveNetworkInfo().isConnectedOrConnecting();
    } else {
      return false;
    }
  }
Пример #17
0
 public boolean isInternetConnectionAvailable() {
   boolean connectionFound = false;
   ConnectivityManager conMgr =
       (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
   if (conMgr.getActiveNetworkInfo() != null
       && conMgr.getActiveNetworkInfo().isAvailable()
       && conMgr.getActiveNetworkInfo().isConnected()) {
     connectionFound = true;
   }
   return connectionFound;
 }
 /**
  * 判断是否连接网络
  *
  * @return
  */
 protected boolean isConnected() {
   ConnectivityManager connectivityManager =
       (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivityManager.getActiveNetworkInfo() != null) {
     if (connectivityManager.getActiveNetworkInfo().isAvailable()) {
       return true;
     } else {
       return false;
     }
   } else {
     return false;
   }
 }
Пример #19
0
 public boolean checkInternetConnection(Context context) {
   ConnectivityManager conMgr =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   // ARE WE CONNECTED TO THE NET
   if (conMgr.getActiveNetworkInfo() != null
       && conMgr.getActiveNetworkInfo().isAvailable()
       && conMgr.getActiveNetworkInfo().isConnected()) {
     return true;
   } else {
     Log.v("INTERNET", "Internet Connection Not Present");
     return false;
   }
 }
 public boolean kontrolEt() {
   final ConnectivityManager conMgr =
       (ConnectivityManager)
           this.context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
   if (conMgr.getActiveNetworkInfo() != null
       && conMgr.getActiveNetworkInfo().isAvailable()
       && conMgr.getActiveNetworkInfo().isConnected()) {
     System.out.println("İnternet Baplantısı var");
     return true;
   } else {
     System.out.println("İnternet Baplantısı yok");
     return false;
   }
 }
Пример #21
0
  public boolean validateConnection() {
    boolean connection;

    ConnectivityManager connectivityManager =
        (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager.getActiveNetworkInfo() != null
        && connectivityManager.getActiveNetworkInfo().isAvailable()
        && connectivityManager.getActiveNetworkInfo().isConnected()) {
      connection = true;
    } else {
      connection = false;
    }
    return connection;
  }
  public void onReceive(Context context, Intent intent) {
    /*ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE );
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(     ConnectivityManager.TYPE_MOBILE );

    if ( activeNetInfo != null )
    {
      Toast.makeText( context, "Active Network Type : " + activeNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
      Intent email1 = new Intent();
      email1.setAction(CONNECTION_INTENT);
      context.sendBroadcast(email1);

      Intent email = new Intent(context, SendEmailConnectChange.class);
      email.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(email);
    }
    else if( mobNetInfo != null )
    {
      Toast.makeText( context, "Mobile Network Type : " + mobNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
      Intent email2 = new Intent();
      email2.setAction(CONNECTION_INTENT);
      context.sendBroadcast(email2);

      Intent email = new Intent(context, SendEmailConnectChange.class);
      email.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(email);
    }*/

    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    // test for connection
    if (cm.getActiveNetworkInfo() != null
        && cm.getActiveNetworkInfo().isAvailable()
        && cm.getActiveNetworkInfo().isConnected()) {
      Log.v(LOG_TAG, "SHAQ: INTERNET CONNECTION FOUND");
      //    	Toast.makeText(context, "Internet found", Toast.LENGTH_SHORT).show();

      Intent connect = new Intent();
      connect.setAction(CONNECTION_INTENT);
      context.sendBroadcast(connect);
      Log.v(LOG_TAG, "BROADCAST CONNECT SENT");
      //        Toast.makeText(context, "BROADCAST CONNECT SENT", Toast.LENGTH_SHORT).show();
    } else {
      Log.v(LOG_TAG, "SHAQ: INTERNET NOT PRESENT");
      //		Toast.makeText(context, "No Internet", Toast.LENGTH_LONG).show();

    }
  }
Пример #23
0
 /**
  * A function to check if there is Internet conn or not - checks both WiFi and Mobile Data
  *
  * @return true if there is Internet conn, false if not.
  */
 public boolean checkConnection() {
   ConnectivityManager connMgr =
       (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
   if (activeInfo == null) return false;
   else return true;
 }
Пример #24
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main12);

    ConnectivityManager cManager =
        (ConnectivityManager) getSystemService(this.CONNECTIVITY_SERVICE);
    NetworkInfo ninfo = cManager.getActiveNetworkInfo();
    if (ninfo != null && ninfo.isConnected()) {

    } else {
      AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
      builder1.setMessage("Sorry There is no internet please check your connection!");
      builder1.setCancelable(true);
      builder1.setPositiveButton(
          "I Will!",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              dialog.cancel();
            }
          });

      AlertDialog alert11 = builder1.create();
      alert11.show();
    }

    itemlist = new ArrayList<RSSItem>();

    new RetrieveRSSFeeds().execute();
  }
Пример #25
0
  public static boolean isInternetAvailable(Context context) {
    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return (activeNetwork != null && activeNetwork.isConnectedOrConnecting());
  }
Пример #26
0
  /**
   * Used to check for a data connection. Will alert the user if connection is unavailable.
   *
   * @param _context Context
   * @return boolean to show if a data connection is available.
   */
  public boolean checkInternet(final Context _context) {

    // Create the ConnectivityManager and check for active network
    ConnectivityManager cm =
        (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
      // Connection is good
      return true;
    } else {
      // No connection, alert the user and return a false.
      new AlertDialog.Builder(_context)
          .setTitle("No Internet")
          .setMessage(
              "Internet connectivity is unavailable, please enable your internet connection and try again.")
          .setPositiveButton(
              android.R.string.yes,
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {}
              })
          .setIcon(android.R.drawable.ic_dialog_alert)
          .show();
      return false;
    }
  }
Пример #27
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);
    listView = (ListView) findViewById(android.R.id.list);
    Intent intent = getIntent();

    String stringUrl = urlText;
    ConnectivityManager connMgr =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
      new DownloadFilesTask().execute(stringUrl);
    } else {
      Log.v("info", "network ocnnection unaavailable");
      // textView.setText("No network connection available.");
    }

    // Bundle extras = intent.getExtras();

    // this.historyArray = new ArrayList<QuestionResponseModel>();
    // if(null!=intent) {
    // this.historyArray =
    // (ArrayList<QuestionResponseModel>)intent.getSerializableExtra("historyArray");
    // }
    // historyArray.
    // Log.v("testing", "thisishistoyarray"+historyArray.size());

    //        adapter = new HistoryAdapter(this, android.R.layout.simple_list_item_2, qrArray);
    //        listView.setAdapter(adapter);
  }
Пример #28
0
 /** do not use frequently */
 public boolean isConnectState() {
   ConnectivityManager manager =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo networkInfo = manager.getActiveNetworkInfo();
   if (networkInfo != null && networkInfo.isConnected()) return true;
   return false;
 }
Пример #29
0
  @Override
  public void onReceive(Context context, Intent intent) {
    int extraWifiState =
        intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);

    switch (extraWifiState) {
      case WifiManager.WIFI_STATE_ENABLED:
        Toast.makeText(act, "Wifi Habilitada", Toast.LENGTH_SHORT);

        ConnectivityManager conMan =
            (ConnectivityManager) act.getSystemService(Context.CONNECTIVITY_SERVICE);
        while (conMan.getActiveNetworkInfo() == null
            || conMan.getActiveNetworkInfo().getState() != NetworkInfo.State.CONNECTED) {
          try {
            Thread.sleep(2000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
        Toast.makeText(act, "Wifi Conectada", Toast.LENGTH_SHORT);
        break;

      case WifiManager.WIFI_STATE_DISABLED:
        alertDialog.show();
        Log.d("AlertDialog", "un dialogo");
        break;
    }
  }
 private void refresh() {
   ConnectivityManager cM = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo infos = cM.getActiveNetworkInfo();
   if (infos != null && infos.isAvailable() && infos.isConnected()) {
     for (int i = 0; i < tab.size(); i++) {
       new WeatherAccessDataAsync(this)
           .execute("DAYS", this.tab.get(i), "com.intent.action.ALLRECEIVE");
       new WeatherAccessDataAsync(this)
           .execute("ACTU", this.tab.get(i), "com.intent.action.ALLRECEIVE");
       new WeatherAccessDataAsync(this)
           .execute("DETAILS", this.tab.get(i), "com.intent.action.ALLRECEIVE");
     }
   } else {
     Intent intent;
     for (int i = 0; i < this.tab.size(); i++) {
       intent = new Intent("com.intent.action.ALLRECEIVE");
       intent.putExtra("town", this.tab.get(i));
       intent.putExtra("type", "DAYS");
       sendBroadcast(intent);
       intent.putExtra("type", "ACTU");
       sendBroadcast(intent);
       intent.putExtra("type", "DETAILS");
       sendBroadcast(intent);
     }
     Toast.makeText(
             this,
             "Si vous souhaitez actualiser les données, veuillez vous connecter a un reseau internet.",
             Toast.LENGTH_SHORT)
         .show();
   }
 }