Showing posts with label available. Show all posts
Showing posts with label available. Show all posts

Saturday, 6 April 2013

Android Devices-How to make sure the SD card is present?



Sometimes you want to make sure the hardware is there... .

if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)){

// SD Card is present 

}else{
// SD card not present 
}

Android Network How to make sure the network is available?


This function will return true if the network is available, false if it is not (airplane mode, out of reach, etc.). IMPORTANT : Don't forget to add [HTML_REMOVED] in your manifest, or the line NetworkInfo[] info = connectivity.getAllNetworkInfo(); will crash ! 


      public boolean isNetworkAvailable() {
                   Context context = getApplicationContext();
                   ConnectivityManager connectivity = (ConnectivityManager)
                   context.getSystemService(Context.CONNECTIVITY_SERVICE);

                   if (connectivity == null) {
                        boitealerte(this.getString(R.string.alert),"getSystemService rend null");
                   } else {
                               NetworkInfo[] info = connectivity.getAllNetworkInfo();
                               if (info != null) {
                                                 for (int i = 0; i < info.length; i++)
                                                {
                                                              if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                                                              return true;
                                                               }
                                                }
                               }
               }
         return false;
        }




Disqus for Android