Posts

Code to Update App Automatically From Google PlayStore

  To prompt users to download App automatically from Google PlayStore as soon as an App update is available, use following code: In build.gradle (App Level) file, Add, implementation 'com.google.android.play:app-update:2.1.0' Sync Project Next add in you MainActivity Class( or any Activity that comes after SplashActivity, where I prefer to put this code) Add the following code private static final int REQUEST_CODE_UPDATE = 123; private AppUpdateManager appUpdateManager; Now inside  onCreate() Method, add the following code appUpdateManager = AppUpdateManagerFactory. create (this); appUpdateManager.getAppUpdateInfo().addOnSuccessListener(appUpdateInfo -> {     if (appUpdateInfo.updateAvailability() == UpdateAvailability. UPDATE_AVAILABLE             && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType. FLEXIBLE )) {         try {             appUpdateManager.startUpdateFlowForResu...

How to Add Animation to Android App in JAVA

First, define your animation in XML. For example, let's create a fade-in animation named fade_in.xml in the res/anim directory: res/anim/fade_in.xml: FILE CODE < alpha xmlns: android ="http://schemas.android.com/apk/res/android" android :duration ="500" android :fromAlpha ="1.0" android :toAlpha ="0.0" android :repeatMode ="reverse" android :repeatCount ="infinite" /> Create Image VIew < ImageView android :id ="@+id/blinking_image" android :layout_width ="wrap_content" android :layout_height ="wrap_content" android :src ="@drawable/animation" android :animation ="@anim/blink" /> In your activity or fragment, load the animation using AnimationUtils.loadAnimation() and apply it to the desired view: // Animation Code Block Animation fadeInAnimation = AnimationUtils . loadAnimation ( this , R . anim . blink ); // Find the vie...

Errors while building APK. You can find the errors in the 'Messages' view.

Go to build.gradle (:app) - App Level Add following repositories   repositories { // jcenter() mavenCentral() maven { url 'https://jitpack.io' } google() } Update all dependencies. Now you should be able to build apk.

Using Socket.IO on android Always Returns XHR Poll Error

The problem I faced is strange and typical. Using Socket.IO on android Always Returns XHR Poll Error . Not much help available on the net regd. XHR Poll Error but StackOverflow has a quickfix. Finally the issue was resolved in two steps: 1.  CORS (Cross-Origin Resource Sharing). CORS Configuration: Ensure that your server-side configuration allows cross-origin requests if your client and server are on different domains. 2. In AndroidManifest.xml tweak  android:usesCleartextTraffic Indicates whether the app intends to use cleartext network traffic , such as cleartext HTTP. The default value for apps that target API level 27 or lower is "true". Apps that target API level 28 or higher default to "false". When the attribute is set to "false", platform components, for example, HTTP and FTP stacks, DownloadManager, and MediaPlayer, refuse the app's requests to use cleartext traffic. Since we are running on IT and yet to implement Positive SSL, we have to set...

Get Android App Version No and Display in a Text Field

 This is how we get Version Name of Android App from Google PlayConsole. 1.  In onCreate Method navigationView = findViewById( R . id . nav_view ); if ( navigationView != null ) { getVersionName(); } else { // Handle the case when navigationView is null Toast . makeText (getApplicationContext(), "Navigation Not Initialized" , Toast . LENGTH_LONG ).show(); } 2. Now define getVersionName() private void getVersionName () { Menu menu = navigationView .getMenu(); MenuItem nav_version = menu .findItem( R . id . nav_version ); PackageInfo pinfo ; try { pinfo = getPackageManager().getPackageInfo(getPackageName(), 0 ); String versionName = "App Version: " + pinfo . versionName ; nav_version .setTitle( versionName ); } catch ( PackageManager . NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Here we have added a menu item inside DrawerLayout to display version...

App Update Request for Android App :: Check Google PlayStore for Updated Version - Download - Install Update

App Update Request for Android App :: Check Google PlayStore for Updated Version - Download - Install Update. OK. Google has made this task easy for us. Here goes the steps: 1) Add this line of code in build.gradle file implementation 'com.google.android.play:core:1.12.0' 2) Inside onCreate Method, write appUpdateManager = AppUpdateManagerFactory . create ( this ); appUpdateManager .getAppUpdateInfo().addOnSuccessListener(appUpdateInfo -> { if (appUpdateInfo.updateAvailability() == UpdateAvailability . UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed( AppUpdateType . FLEXIBLE )) { try { appUpdateManager .startUpdateFlowForResult( appUpdateInfo, AppUpdateType . FLEXIBLE , this , REQUEST_CODE_UPDATE ); } catch ( Exception e) { e.printStackTrace(); } } }); 3) Now add following methods @Override protected void on...

Android Navigation Drawer Menu

 Creating Android Navigation Drawer Menu is a complex task involving bunch of steps. So, let's start. 1) In activity_main.xml file change the root level layout to  DrawerLayout. So whatever layout is there, make it  DrawerLayout at the very beginning. 2) Add NavigationView before the closing TAG of DrawerLayout < com.google.android.material.navigation.NavigationView android :layout_width ="wrap_content" android :layout_height ="match_parent" android :layout_gravity ="start" android :fitsSystemWindows ="true" android :id ="@+id/navigationView" /> 3) Add following properties inside the opening DrawerLayout android :fitsSystemWindows ="true" tools :openDrawer ="start" 4) Now Create a LayoutResouceFile and name it as header.xml. We will use this file as the header for DrawerLayout <? xml version ="1.0" encoding ="utf-8" ?> < LinearLayout xmlns: android ="htt...