Wednesday, November 16, 2011

Android :connot see the image/file/video that has been saved by application on SD card

Well this thing may cause a head-storm

Scenario :
Your application has saved/write a file/picture/video that is not being reflected in the gallery.
The reason behind this is that media Scanner is not aware of the new files ..

So the Simple solution to this problem is

try Running this piece of code after u have closed your output stream after writing the file:


MediaScannerConnection.scanFile(context, new String[] { filePath+fileName }, null, null);

Tuesday, November 15, 2011

Android Loading Dialog Box

By this you can show a loading dialog box to the user while performing a background task


First declare the ProgressBar and its Handler:


    ProgressDialog progressBarDialog;
     Handler handler=new Handler() {
             @Override
             public void handleMessage(Message msg)
             {
                
                 if(progressBarDialog != null)
                 {
                     progressBarDialog.dismiss();
                
                        ///Write the code u want to perform after the previous task was completed
                 }
                
             }
         };
   

Place the task/function/code u want to perform inside run()

progressBarDialog = ProgressDialog.show(PhoneLog.this, "Cyber Sports", "Saving...", true);
                        new Thread()
                        {
                            public void run()
                            {
                                GenerateResponse();///example of the task u want to perform
                                handler.sendMessage(handler.obtainMessage());
                            }
                        }.start();

And its done!!

Android Check intertnet connection is available or not

  //////Check Internet Connection return True or False  ///////

        public static boolean isInternetAvailable(Context context)
        {
             boolean isInetrnetAvailable = false;
             try
             { 
                  ConnectivityManager connectivityManager = (ConnectivityManager)   
                   context.getSystemService(Context.CONNECTIVITY_SERVICE);
                  NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
               
                  if(networkInfo != null)
                  {  
                       if( networkInfo.isConnected())
                       {
                           isInetrnetAvailable  = true;
                       }
                       else
                       {
                           isInetrnetAvailable  = false;
                       }
                  }
                  else
                  {
                      isInetrnetAvailable = false;
                  }
             }
             catch(Exception exception)
             {
                 isInetrnetAvailable = false;
             }
             
             return isInetrnetAvailable;
        }


------------------------------------------
in addition  you can navigate the user to Wireless and Network settings through calling ....

 startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));