Skip to main content

Posts

Showing posts from June, 2019

How to Check Internet Connectivity Programmatically

Most of Android Applications use Internet Connection for Performing their Task .So here is Some code Snippet to Check whether the App is Connected to Internet Connection Or Not ? So lets Start :- Step 1:  First we Create a Utility Class fro Checking Internet Connection  ApplicationUtility.Java public class ApplicationUtility { ConnectivityManager connectivityManager; NetworkInfo info; public boolean checkConnection(Context context) { boolean flag = false; try { connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); info = connectivityManager.getActiveNetworkInfo(); if (info.getType() == ConnectivityManager.TYPE_WIFI) { System.out.println(info.getTypeName()); flag = true; } if (info.getType() == ConnectivityManager.TYPE_MOBILE) { System.out.println(info.getTypeName()); flag = true; } } catch

How to Check the Activity open First time using Shared Preference

Sometimes we want to show some App Introduction and other things as per our requirements so here i am sharing code snippets to determine that the activity open first time using Shared Preference  . So Lets Start :-  for example you want to open App Introduction of your app before going to Main Activity Class so in Main Activity Check that the Activity Opening First time or not Using these lines of Code. Thread t = new Thread(new Runnable() { @Override public void run() { // Intro App Initialize SharedPreferences SharedPreferences getSharedPreferences = PreferenceManager .getDefaultSharedPreferences(getBaseContext()); // Create a new boolean and preference and set it to true Boolean isFirstStart = getSharedPreferences.getBoolean("firstStart", true); // Check either activity or app is open very first time or not and do action if (isFirstStart) { // Laun