Reputation: 1399
I tried to store text file in phone memory of the device, It was working with which device support external slot., but it is not working with android phone which doesn't have external slot.( For Example Samsung S6 Edge).
Here is my Code:
public void AfterSaveClick() {
OutputStream fOut = null;
try {
Toast.makeText(MainActivity.this, "Start",Toast.LENGTH_SHORT).show();
//device basic path(phone memory)
File root = new File(Environment.getExternalStorageDirectory()
+ File.separator + "Log_Folder" + File.separator);
root.mkdirs();
File phoneMemoryTextMainDirectory = new File(root, "samples.txt");
FileWriter writer = new FileWriter(phoneMemoryTextMainDirectory);
writer.append("Hello");
writer.flush();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 0
Views: 108
Reputation: 642
I think what you should do is check first if the device has external storage, you can use something like this:
Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
if the device has external storage then use the path that you already have, otherwise you should add another path inside the phone's internal memory.
Upvotes: 1