Friday, April 8, 2011

METHOD TO CHECK WIFI IS AVAILABLE OR NOT

 The following method Return whether Wi-Fi is enabled or disabled.
 True if enabled otherwise false.
 
 public boolean checkWIFI()
 {
        WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        return wm.isWifiEnabled();
 }

METHOD TO CHECK INTERNET IS AVAILABLE OR NOT

The following method returns true if internet is available and false if not available.

public boolean checkInternetAvailablity() 
{
         ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);                                         
          return cm.getActiveNetworkInfo().isConnected();

}

REMOVING DULL BACKGROUND WHILE RUNNING PROGRESS DIALOG

While running progress dialog the screen becomes dull. In order  to avoid that blur the following code will helpful.

Here i am applying properties to our progress dialog. In this example "lp.dimAmount:" is the attribute to set the dim amount .

pdlg = ProgressDialog.show(getParent(), "", "Loading..");
 //Setting the properties
WindowManager.LayoutParams lp = pdlg.getWindow().getAttributes();
 lp.dimAmount=0.0f;
//Applying to the screen
 pdlg.getWindow().setAttributes(lp);

SHOWING PROGRESS DIALOG WHILE DOWNLOADING USING THREAD

hi ...

In your application u want to get the data from the server. In this example i am putting all that parsing logic in a thread and showing progress dialog while loading the data. After getting all the data i am dismissing the dialog.
The following example illustrates the same ...


public void parsing()
{
        ProgressDialog pdlg ;
      
       //SHOWING DIALOG
        pdlg = ProgressDialog.show(getParent(), "", "Loading..");
        Thread thr_parsing = new Thread()
        {
            public void run()
            {
               //do the parsing
                runOnUiThread(new Runnable()
                {                   
                    @Override
                    public void run()
                    {   
                            //DISMISSING THE DIALOG
                            pdlg.dismiss();
                    }
                });
            }
        };
        thr_parsing.start();
       
    }