Category: Android Code

February 4, 2020

Cleartext HTTP traffic not permitted

When you updated the android SDK version of your project from 26 to 29 and the app is making the Http API call using http instead of https. You are facing an issue that your app is not connecting to the server and there is an error in the logcat Cleartext HTTP traffic to * not permitted. Do not get worry in this post […]

January 28, 2020

How to install apk file on android emulator

Sometimes you do not have android device to test the andorid app (apk). But don’t worry you can install the android app on the emulator. It is very easy to install and test the app on android emulator. For this even you do not require any IDE or any development experience. In this post, I have will show you how to install any external app […]

October 14, 2017

How to disable back button in android

When user presses back button to Disable Back Button in android and you want to perform any of the action instead of exit from the app. Like you have seen in many app when user presses back button to exit an app a toast message is displayed with message “press again to exit” or a dialog is displayed to “rate the app”. Its very easy […]

April 20, 2017

Android How to convert Dp to Px and Px to Dp

If you are developing an android application that is based on inflating views at runtime and are dependent on height and width of the screen. You often need to Convert Dp to Px android and convert between real pixel (px) and device independent pixel (dp, dip). Most of the use case of converting dp to pixels come when you are inflating a view from code. […]

April 20, 2017

What is the difference between “px”, “dp”, “dip” and “sp” on Android

When you are creating the UI layouts of your application, you usually define dimensions with units like px, dp, dip and sp. Pixels(px) – corresponds to actual pixels on the screen. This is used if you want to give in terms of absolute pixels for width or height. Density-independent Pixels (dp or dip) – an abstract unit that is based on the physical density of […]

January 16, 2017

What is Context in Android

What is Context in Android? Android is an interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc. Different ways of getting context → getContext() → getBaseContext() → getApplicationContext() → this […]

January 15, 2017

How to Get Current Screen Orientation in Android

Android devices have both landscape and portrait modes and can flawlessly move between these modes. The Android working framework naturally handles these progressions for your application. You can also detect in which orientation is your android device. The natural orientation of a device is the orientation in which the orientation is 0 on all the three axes. Below method returns the current screen orientation mode […]

January 14, 2017

Android How to Get Phone Unique Device Id

Sometimes it is required to get the unique ID of android device while developing the android application. This is necessary in cases when the you wants to track the unique device installations of the application. There are many ways to get android device unique ID so below method is a relevant way to get ANDROID_ID via Secure class. Below method returns a 64-bit number (as […]

January 4, 2017

Android How to Check Internet Connection Status

If you are developing an android application that perform internet related operations like calling web API, loading web page in Web View, uploading profile pic and etc. So before performing any internet related tasks it is better to first check that your device is connected to internet or not . Android provides ConnectivityManager class to know about the internet connection status. The following method will […]

January 3, 2017

How to Hide and Show Soft Keyboard in Android

There may be a case where you want to hide or show the soft keyboard. The case may be for example, you are done with entering text in search view and based on your selection from the suggestion list you want to take some action and also want to close (hide) the soft keyboard. You can hide or show the soft keyboard programmatically in Android […]