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 Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply