Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move spcific apps to/from sd card using ADB?

Background

It is possible to set the default installation to the SD card by using (based on this link) :

for pre- API14 :

adb shell pm setInstallLocation 2 

for API 14 and above:

adb shell pm set-install-location 2 (Android 4.x)

The problem

This only works for newly installed apps (or you just go manually over each of them and set it there), but I would like to know how to re-install an already installed app into the SD card (and also back to the internal storage).

What I've tried

I tried to read the commands available via ADB, and tried to run the next command:

adb shell pm install -s -r -i com.example.test

But it didn't work

The question

Suppose an app is already installed on the internal storage (or the SD card), how can I use ADB to re-install it to the SD card (or the internal) ?

like image 561
android developer Avatar asked Mar 19 '23 19:03

android developer


1 Answers

Apparently, need to provide the location of the APK rather than the package name.

Following worked on my end for VLC that I installed from Play Store and was originally located in internal storage:

$ adb shell pm install -s -r /data/app/org.videolan.vlc.betav7neon-1.apk
    pkg: /data/app/org.videolan.vlc.betav7neon-1.apk
Success
$

And moving back to internal storage:

$ adb shell pm install -f -r /mnt/asec/org.videolan.vlc.betav7neon-1/pkg.apk
    pkg: /mnt/asec/org.videolan.vlc.betav7neon-1/pkg.apk
Success
$

Update 1

Following are respective commands with -i: specify the installer package name option.

Move to SD card:

$ adb shell pm install -i "com.android.vending" -s -r /data/app/org.videolan.vlc.betav7neon-1.apk
    pkg: /data/app/org.videolan.vlc.betav7neon-1.apk
Success

Move to internal storage:

$ adb shell pm install -i "com.android.vending" -f -r /mnt/asec/org.videolan.vlc.betav7neon-1/pkg.apk
    pkg: /mnt/asec/org.videolan.vlc.betav7neon-1/pkg.apk
Success

Update 2

Using -i is optional, but if it is not used the installer information is lost during movement:

$ adb shell pm list packages -3 -i
package:org.videolan.vlc.betav7neon  installer=com.android.vending

$ adb shell pm install -s -r /data/app/org.videolan.vlc.betav7neon-1.apk
    pkg: /data/app/org.videolan.vlc.betav7neon-1.apk
Success

$ adb shell pm list packages -3 -i
package:org.videolan.vlc.betav7neon  installer=null

Hope this helps.

like image 173
ozbek Avatar answered Apr 02 '23 16:04

ozbek