I am running android test using Cucumber.The reports of the test are being stored in /data/data/pkg_name/cucumber-reports.Now I need that content inside "cucumber-reports" folder.I used copy command to copy the cucumber reports folder from internal storage to Public External Directory(PICTURES) which is working in Marshmallow.But when I ran in Nougat,I am unable to copy that folder to External Directory.I am unable to access the folder on Android 7+ version device as due to the introduction of new file permission changes.
Without FileProviders,I am using execute Shell command of Instrumentation to copy"cp" folder from internal app dir to External Dir. Please find the copy code below:
public static void copyReportsToPublicDirs(Scenario scenario) {
try {
File externalStoragePublicDirectory= Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES);
String extStrPath= externalStoragePublicDirectory.getPath()+"/"+"cucumber-reports";
new File(extStrPath).mkdirs();
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
String command = "cp -R -f "+"/data/data/"+ BuildConfig.APPLICATION_ID+"/cucumber-reports "+extStrPath;
Log.println(Log.INFO,"Copy Reports to SD Card","Performing copy the reports to SD Card");
ParcelFileDescriptor pfd =instrumentation.getUiAutomation().executeShellCommand(command);
if(pfd.canDetectErrors())
Log.println(Log.INFO,"Error displayed","Copy Error");
} catch (Exception e) {
e.printStackTrace();
}
}
The above code works fine on Marshmallow but on Nougat,I am not seeing the folder and its contents not copied from it. By what ways,can I retrieve the cucumber report folder inside data/data to External Dir?