Answer the question
In order to leave comments, you need to log in
Android Dev: Saving data to SD card for MediaTek ("Portable Player") based devices?
There are many budget smartphones and tablets based on MediaTek, in which the chipset chip has a model of the MTxxxx type, for example MT6571.
"Chip set" - "a set of chips in one microcircuit package", in particular, there is a CPU, GPU and others, and there is also a controller that "goes out" to the USB connector and provides access to data.
In devices with different chipsets, respectively, this controller also differs.
Let's say, for Qualcomm-based smartphones, the approach to implementing this controller is correct.
There is the same controller as in USB flash drives, the smartphone is recognized as a "Removable disk", and uses the appropriate "protocol" for data exchange with the PC file system driver, the implementation of which works well, and I do not remember any "jambs",
But for some reason, MediaTek decided to use a different technology - the one in MP3 players. This is MTP, and its implementation by Windows is WPD.
Probably, Media Tek previously dealt with multi media and did not want to (as it seemed to them) "reinvent the wheel". There are many such cases.
And this system is "sharpened" specifically for working with multimedia, and for a smartphone or tablet, which is a full-fledged multifunctional computer, it does not fit well.
First of all, when connecting to a PC and opening the "SD card", not only do we have to click an extra time to open the device first, and then the map (and we still can't get the full path to the map), but in addition it loads very slowly file tree.
But that's what, but let's try to save the file to the SD card from our Android application:
//android.permission.WRITE_EXTERNAL_STORAGE
new File(Environment.getExternalStorageDirectory(), "file.txt").createNewFile();
MediaStore
, which on this device notifies the controller, and it already notifies the PC. MediaStore
, as expected:ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, fileabsolutepath);
context.getContentResolver().insert(Files.getContentUri("external"), values);
MediaStore
. Answer the question
In order to leave comments, you need to log in
Your thinking is correct, but the implementation is not entirely correct. You really need to notify MediaStore about the appearance of a new file (and deletion, of course, too). But it's done like this:
String fileAbsPath = "file.txt";
new File(Environment.getExternalStorageDirectory(), fileAbsPath).createNewFile();
MediaScannerConnection.scanFile(context, new String[]{fileAbsPath}, null, null);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question