Showing posts from 2016

Show the updated battery status in Android

Have a happy holidays. After a long time, I'm blog here such a good topic.

Here I explain about the battery status on real time. Yes, you can use BatteryManager to get the battery status. But you want to know the updated status on all time means, you need to use BroadcastReceiver.

You can add on your activity.

 private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {

            int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
            int icon_small = intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, 0);
            int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
            int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
            boolean present = intent.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
            int status = intent.getIntExtra(BatteryMa…


http - hyper text transfer protocol
xmpp - eXtensible messaging and presence protocol.

Both http and xmpp is communication protocol and open source. But their uses is completely different.

XMPP is mostly used in chat type application. XMPP is faster than HTTP. It's a bi-directional functionality.

Like chat application, user sends message from device, it's re-directs to server and receive's message to another user. It's handle both upstream and downstream.

Proguard usage in Android

Hi friends, have a great day. Now I'm going to explain the what is proguard and it's usage in android. Believe android is big sea, there is lot of things.

What is Proguard?
Proguard is a simple java tools to shrink apk, prevent re-engineering from hackers. It's a reduce the size of android apps and run faster. Proguard renames the classes, methods and objects to prevent the re-engineering the APK.

Now hackers easily to hack your code and run for their uses. Proguard stops them and protect your code.

In android project, proguard located in apps folder.

To enable the code shrinking, just add simple line in gradle. It's under

      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

Please follow the below lines, that's very important to make it.

#Specifies not to generate mixed-case class names while obfuscating. By default, obf…

Speed up gradle build in Android Studio.

Hi friends, have a great day. In android development, initially most of developers are learn on eclipse, then android studio came with a lot of features. Most of developers hate because of GRADLE. In eclipse, we using maven. But gradle is completely different.

Take a long time for making a build.

Please don't take seriously, if you have enough RAM, Internet and good speed of processor. :)

I give some suggestion to perform the faster gradle build.

1. Append the following lines in in your app.

# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
# org.gradle.daemon=true

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects.
# org.gradle.parallel=true

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSiz…

Singleton classes

Most of interviewers asking the question to java and android developers. It's not strange. We need to explore this.


Create the only one instance in the class.Provide a global point of access to the object Allow multiple instances in the future without affecting a singleton class's client
In android applications, It's help to hold the global session data. It's easily to call from another class.
Imagine, If you creating the MyApplication class, that's need to be access in all over the application means.
private static MyApplication sInstance;
public static MyApplication getInstance(){       return sInstance; }
public void onStart(){ --- }
public void onTerminate(){ -- }
public void onPlay(){ -- }
If you want to access onStart(), onTerminate() or OnPlay() methods from another classes means, you need to use singleton.
So buddies, I hope you clear now. If you not clear, please practice. :)

Useful ADB commands list

Hi everyone, have a nice day. Sometimes we forget about what terminals can do, but terminals is much better than UI views. It's much faster than the UI prompting. In android, they are so much ADB commands are there, but I don't like to confuse. Just represents important commands in ADB,

Adb path: C:\Users\Username\AppData\Local\Android\Sdk\platform-tools

Wifi debug
adb tcp ip portnumber(Ex: 5555)

adb connect ip address portnumber (Ex: adb connect

adb devices -> list the devices.

adb kill-server -> Terminate the adb server process.

adb install test.apk -> Install the apk.

adb install -l test.apk -> forward lock application.

adb install -r test.apk -> replace existing application.

adb install -t test.apk -> allow test packages.

adb install -s test.apk -> install application on sdcard.

adb install -d test.apk -> allow version code downgrade.

adb install -p test.apk -> partial application install.

adb uninstall com.test.ap…

Checking the permission above marshmallow (API 23)

Android Marshmallow completely different from previous version of lollipop. Because they need to check and request the permissions in run time. If permission requires to change, need to apply immediately else can't access those features.

For more details refer the developer site

Here I give some code, just try it.

if (currentapiVersion >= android.os.Build.VERSION_CODES.M) {
                int hasLocationPermission = checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION);
                int hasSMSPermission = checkSelfPermission(android.Manifest.permission.SEND_SMS);
                int hasAccessLocation = checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION);
                int hasGetAccounts = checkSelfPermission(android.Manifest.permission.GET_ACCOUNTS);
                int hasInternet = checkSelfPermission(android.Manifest.permission.INTERNET);
                int hasAccessNetwork = checkSelfPermission(android.Manifest.permission.ACCESS_NETWORK_…

Java set location problem for android studio

Hi, After a long time I came again in blog. Now we start moving forward. 
Some peoples want to develop the android using jdk 1.7 and some peoples choose jdk 1.8. Most of times we struggle of choosing right one
What's new with JDK 1.8 Lamba ExpressionsSmall VMParallel array sortingBulk data operations for collectionsand more... Some users installed both java, but can't able to choose the jdk. And have some problems in android studio they choose the first time installed configuration, can't able to change the jdk in settings. 
if you want JDK location changes back to 1.7 every time it is updated to 1.8 path
If you've been upgrading your Android Studio and importing settings from previous installations, this might happen (it might also happen with a fresh installation).
So go to config folder is located in android studio.(Example: $HOME/.AndroidStudio2.1/confg)
Open the options folder --> delete jdk.table.xml (Take a backup, in case have some problem)
Restart the andro…