Monday, July 9, 2012

Get Screen Brightness

In general the screen brightness varies in between 0 to 255. The below snippet helps to find the screen brightness.

public static int getScreenBrightness(Context context)
{
          try
          {
              return Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
          }
          catch (SettingNotFoundException e)
          {
              Log.e("getScreenBrightness()", ""+e.getMessage());
              return -1;
          }
}

We have to pass context of the activity from where we are calling this method.

This method will return screen brightness as a result.

Getting WI-FI strength in percentage

The below snippet helps to find the WI-FI strength in the percentage.

public static int getWifiStrength(Context
{
          try
          {
              WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
              int rssi = wifiManager.getConnectionInfo().getRssi();
              int level = WifiManager.calculateSignalLevel(rssi, 10);
              int percentage = (int) ((level/10.0)*100);
              return percentage;
          }
          catch (Exception e)
          {
              return 0;
          }
}


We have to pass context of the activity from where we are calling this method.

It will return WI-FI strength in percentage. In case if any exception found then it will return 0;

Get Application version based on package name

The below snippet helps to find the application version

public static String getVersionName(Context context, String strPkgName)
{
         try
         {
            return context.getPackageManager().getPackageInfo(strPkgName, 0).versionName;
         }
         catch (NameNotFoundException e)
         {
            Log.e("getVersionName()", ""+e.getMessage());
            return "";
         }
}

Here we have to pass context of the application and package name of the application that you want to find the version.

If the application exists(Installed) in the mobile then it will return the application version as string. otherwise it will return empty string.

Tuesday, April 17, 2012

Way to find device screen category (small, normal, large, xlarge)

The below snippet helps to find the screen catogory

public void getScreenSize()
      {
          switch (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
          {
              case Configuration.SCREENLAYOUT_SIZE_SMALL:             
                  Toast.makeText(Home.this, "SMALL SCREEN", Toast.LENGTH_LONG).show();
                  break;
           
            case Configuration.SCREENLAYOUT_SIZE_LARGE:
                Toast.makeText(Home.this, "LARGE SCREEN", Toast.LENGTH_LONG).show();
                break;
           
            case Configuration.SCREENLAYOUT_SIZE_XLARGE:
                Toast.makeText(Home.this, "XLARGE SCREEN", Toast.LENGTH_LONG).show();
            break;
           
            case Configuration.SCREENLAYOUT_SIZE_NORMAL:
                Toast.makeText(Home.this, "NORMAL SCREEN", Toast.LENGTH_LONG).show();
            break;

         }

Tuesday, April 10, 2012

Get Available Internal Memory

The below snippet helps to find the available internal memory. It will return the result in MB.

/**
       * Calculates the available internal memory
       * @return internal memory available in float
       */
      private float getAvailableInternalMemory()
      {
              float availMB;
              File path ;
              StatFs stat;       
              long blockSize;           
              long availableBlocks;
              try
              {
                  path = Environment.getDataDirectory();
                  stat = new StatFs(path.getPath());
                  blockSize = stat.getBlockSize();
                  availableBlocks = stat.getAvailableBlocks();
                  availMB = (availableBlocks*blockSize)/(1024*1024);               
              }
              catch (Exception e)
              {
                  availMB = -1;
              }         
             
              return availMB;
      }

Monday, March 26, 2012

Overriding Home Key Android

After a deep search i came to know that there is a possibility to lock(Disable) home key in the android like back key. It was pretty easy. Add the below snippet to the activity in which you want to disable home key click...


@Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}

Thursday, February 23, 2012

Expense Manager

Cool App ... Check it out from Android Market


The Expense Manager helps you to organize your expenses in a proper way. This app reduces the overhead of maintaining our expenses in a diary and tracking at the end of the month. Using this app we can track the expenses based on different options like By Category, Date, Month, year and Payment Mode in a simple way.



Available in Android Market