shell script to check if android application is installed, find an apk path and uninstall if its already installed or install new apk if application is not installed

Following shell script does,

  • check if android application is installed
  • find an apk path
  • uninstall if its already installed
  • install new apk if application is not installed

 

#!/bin/bash
ADBPATH=/usr/bin/adb
PACKAGE_NAME=my.v1rtyoz.helloworld
LOCAL_DESKTOP_APK_PATH=$PWD/PACKAGE_NAME.apk

IS_PACKAGE_EXISTS=`$ADBPATH shell pm list packages $PACKAGE_NAME`
echo "pm list package returned: $IS_PACKAGE_EXISTS "
if test -n "$IS_PACKAGE_EXISTS"
then
        echo "Application $PACKAGE_NAME exists"
        CMD=`$ADBPATH shell pm path $PACKAGE_NAME`
        APK_PATH=${CMD:8}
        APK_PATH=$(echo $APK_PATH|tr -d '\n'|tr -d '\r')
        echo "Application is installed at path $APK_PATH"

        echo "uncomment below line if you want to uninstall app"
        echo "$ADBPATH uninstall $PACKAGE_NAME"
        #$ADBPATH uninstall $PACKAGE_NAME
else
        echo "Application $PACKAGE_NAME not found"
        echo "we can install a new apk now"
        $ADBPATH install $LOCAL_DESKTOP_APK_PATH/$PACKAGE_NAME.apk

fi
Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Multimedia - Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question