Requirements: I need to use adb
to store a string value somewhere on an Android device that later is to be consumed by the app I'm programming upon first launch. The app is not installed when the String value is to be stored. The following requirements apply:
Methods attempted:
/sdcard/Downloads
. Does not work because of tightened permission model from Android 11 and above/sdcard/Android/data/com.my.app/files/
. Does not work because the folder is cleared on install on some (not all) devicesedit: I need this for a specific CI/CD config scenario. This is not something I will ship into the wild.
The closest solution to your requirements is to use a custom system property.
adb
adb shell setprop debug.foobar 'customString'
works while adb shell setprop foobar 'customString'
won't workNot sure how you didn't find How to define and use a system property in Android Instrumentation test?
but this answer works as tested on a Samsung Galaxy S9 Android 10 and a Pixel 6a Android 13.
Just be aware of when you are setting/unsetting custom system property values and when those are checked in the app under test, i.e. you may need to kill the app under test so that updated values are picked up.
As @Robert and @DiegoTorresMilano mentioned in the comments a ContentProvider/ContentResolver would be another solution. A second persistent app which would provide configuration test values to the app under test. That would be a solution for environments where 'developer mode' is unavailable OR where custom commands via adb
impose a burden.