Friday, February 28, 2014

Customize Toast Example Code

public class ToastUtil {
  /**
   * @param context
   * @param text text to be shown on toast
   * @param val toast duration
   * @param color background color for toast
   * @param size toast text size
   * @param textColor toast text color
   * @return
   */
  public static Toast makeText(Context context, CharSequence text, int val, int color, float size,
      int textColor) {
    Toast toast = new Toast(context);
    TextView tv = new TextView(context);
    tv.setText(text);
    tv.setBackgroundColor(color);
    tv.setTextSize(size);
    tv.setTextColor(textColor);
    toast.setView(tv);

    toast.setDuration(val);
    toast.show();
    // return toast;
    return toast;
  }
}

USE Below Code to show Toast:
 ToastUtil.makeText(this, "welcome", Toast.LENGTH_SHORT, Color.GREEN, 30, Color.RED).show();

Monday, February 10, 2014

How to disable/enable Wi-Fi in android device programatically

public static void changeWifiStatus(Context context, boolean status) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wifiManager.setWifiEnabled(status);
  }


permission:
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

How to get Android device IMEI number programatically

TelephonyManager telephonyManager = (TelephonyManager) context
        .getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.getDeviceId();

permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

How to show GPS - settings page

 You can check Gps Settings  with
((LocationManager) this.getSystemService(Context.LOCATION_SERVICE))
        .isProviderEnabled(LocationManager.GPS_PROVIDER)
and show gps settings screen to user by using
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
              startActivity(intent);