简体   繁体   中英

Pull file from Android sdcard using gradle task

I want to run a task in gradle which will pull a file placed on Android device sdcard. Below is the code I am trying.

File copyFile = new File("/storage/emulated/0/abc.png")
project.logger.warn("copy file path:"+copyFile.getAbsolutePath())
if (copyFile.exists()) {
      project.logger.warn("file exist:yes")
 }else{
      project.logger.warn("file exist:no")
}

The problem is the file exists on sdcard, still I get the message in else part "file exist:no".
Can anyone help me to get the file on sdcard?

Gradle runs on your development machine. It not running on your Android device. Your development machine does not have a /storage/emulated/0/abc.png file.

You are welcome to try to have Gradle run an adb pull command to pull the file from the device to your development machine. This Gradle plugin may make this task easier, though I have not tried it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM