I am making an app that will fetch the server logs and store it in end-users android phone. I am reading and writing the file using InputStream and FileOutputStream which generates a new text file under data/data/<package_name>/files folder of Emulator. However, it is not showing in my physical android device when connected through USB. Used below logic:
try{
Session session = new JSch().getSession(user, host, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
InputStream inputStream = sftpChannel.get(remoteFile);
try (Scanner scanner = new Scanner(new InputStreamReader(inputStream))) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
logs.append(line);
}
try {
FileOutputStream fos = null;
fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
fos.write(logs.getBytes());
Toast.makeText(this, "File Saved", Toast.LENGTH_SHORT).show();
}
catch(FileNotFoundException e){
e.printStackTrace();
}
catch (JSchException | SftpException e) {
e.printStackTrace();
}
Is there any way, I could view this file in my phone without rooting and giving some permissions or any better alternative? Highly appreciate your inputs guys.
Device File Explorer Snapshot
question from:
https://stackoverflow.com/questions/66051626/file-under-data-data-package-name-files-not-showing-in-my-android-device 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…