I know that in Android I can read files from disk this way:
Uri uri = Uri.parse("file:///data/data/com.example.mytest.mytest/test.txt");
InputStream stream = getContentResolver().openInputStream(uri);
int i;
while ((i = stream.read()) != -1) {
Log.i("@@@", "znak: " + i);
}
However, I don't know how it works. Does exist in Android some content provider that works with "file" scheme? But how - I thought that the scheme of URIs of all content providers must have "content" scheme?
ContentResolver
and openInputStream()
handle file:
schemes directly. This is covered in the documentation for openInputStream()
.
Also, do not hardcode paths. Your Uri
is wrong on millions of devices:
on Android 4.2+ tablets and Android 5.0+ phones, for guest and other secondary accounts
on Android M devices, if the user "adopts" removable storage and moves apps to it