Last updated: Jun 23, 2020 13:55
When media files (such as images or music files) are transferred to a device through API calls, Android apps like Gallery and Music may not be aware of the new media and will simply ignore them. This is not a Perfecto limitation, but rather an Android Limitation of not indexing the files when they are not added through the Android UI. Using File Explorer and placing a file on the SDCard will have the same effect.
The solution is to force Android to re-scan the media files. This could be accomplished by using a third-party Media re-scan application, by unmounting and remounting the SDCard, or by adding a step to programmatically force Android to re-scan a specific file upon its transfer. The latter can be achieved by running a simple adb shell script on the Device, as described in the following procedure.
To re-scan a file by running an ADB script:
- Upload a file to the Repository using API.
UploadMedia()method of the PerfectoLabUtils can be used for this. This class is part of the template project for a number of programming languages, which comes with the IDE Plugins.
- Transfer the file to the device using the File Transfer widget.
In automation testing, use the "Put File" function:
To trigger the rescan, use the adb command. This can be tested using DevTunnel to execute the adb command directly.
The adb command that can rescan a specific file (here
lala2.jpg, located in the Camera folder within DCIM) is:
To incorporate this into your test, use a Draft Function:
The complete example to transfer a file to an android device to then re-scan it could look like this: