Blogs

Android: How to get Battery level status more accurately?

Answer posted by Meenu

The main objective of this post is to help you to get all the details of the Battery in Android. Create a BroadcastReceiver in your activity to get all value of battery. double batteryCapacity;

private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

        int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE,-1);
        mTextViewInfo.setText("Battery Scale : " + scale);

        ...   
                         

READ MORE

How can I get netmask from Android device?

Answer posted by Rakesh

Try this.

WifiManager wifiMgr = (WifiManager) getContext().getSystemService(context.WIFI_SERVICE);

   DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo();
 String  s_netmask = String.valueOf(dhcpInfo.netmask);
String   s_ipAddress = String.valueOf(dhcpInfo.ipAddress);
   //use formatter for showing correct ip sequence, firstly convert
  // string into integer beacause formatter take integer.
   String snetamsk = Formatter.formatIpAddress(netamsk);
   String sipadress = Formatter.forma...   
                         

READ MORE

How to get the device's IMEI/ESN programmatically in android?

Answer posted by Rakesh

You can try.

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

 public String getImei() {

    return telephonyManager.getDeviceId();
}
Add below permission into your Androidmanifest.xml file.
< uses-permission android:name="android.permission.READ_PHONE_STATE"/>
...

READ MORE

Android:how to find the android version name programmatically?

Answer posted by Meenu

You can try following function.

public String AndroidOSName() {
    String os = Build.VERSION.SDK;
    System.out.println("here is my os" + " " + os);
    if (os.equals("23")) {
        return "Marshmallow";
    } else if (os.equals("21")) {
        return "Lollipop";
    } else if (os.equals("22")) {
        return "LOLLIPOP_MR1";
    } else if (os.equals("20")) {
        return "KitKat";
    } else if (os.equals("19")) {
        return "KitKat";
    } else if (os.equals(...   
                         

READ MORE

How to get current SIM card number in Android?

Answer posted by Meenu

You can Try following function and its return your sim number.

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

               public String getSIMNumber() {
                    return telephonyManager.getSimSerialNumber();
}
Add below permission into your Androidmanifest.xml file.
< uses-permission android:name="android.permission.READ_PHONE_STATE"/>
...

READ MORE

How to find out carrier's name in Android

Answer posted by Rakesh

You can Try following function and its return your SimOperatoerNumber.

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

public String getSIMoperatorName() {
    return telephonyManager.getSimOperatorName();

}
Add below permission into your Androidmanifest.xml file.
< uses-permission android:name="android.permission.READ_PHONE_STATE"/>
...

READ MORE

How do I get the country code of a user on Android?

Answer posted by Rakesh

You can try the following function. It's returning your country ISO code:

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

        public String getSimCountryIso() {

    return telephonyManager.getSimCountryIso();

}
Add permission below into your AndroidManifest.xml file
< uses-permission android:name="android.permission.READ_PHONE_STATE"/>
...

READ MORE

Get Android Phone Model Programmatically

Answer posted by Bhan

You can Try following function and its return your phoneModel name in string format.

public String phoneModel() {

    return Build.MODEL;
}
...

READ MORE

Get screen resolution of device

Answer posted by Meenu

Try this,

 Display mDisplay =(Context).getWindowManager().getDefaultDisplay();

       mDisplay.getWidth();
       mDisplay.getHeight();
...

READ MORE

Bluetooth isEnabled() fails

Answer posted by Rakesh

To check Bluetooth state, ON programmatically: 1. Add Following Permission : -

android.permission.BLUETOOTH
2. Use Following Function For Enable BLUETOOTH:-
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

private void turnOn() {

   if (!mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new 
        Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivity(enableBtIntent);
    }

}
...

READ MORE