I connect a Samsung Galaxy Android tablet with a USB cable to a computer running Windows 7. It connects via MTP.
- Step 1. Copy my SQLite database from Windows 7 to your tablet through Windows Explorer.
- Step 2. Open it on the tablet (which adds the android_metadata table), and then close it.
- Step 3. Copy the SQLite database back to Windows.
- Step 4. Verify it using sqlite3.exe. It is damaged.
Now another test.
- Step 1. Copy my SQLite database from Windows 7 to your tablet using Windows Explorer
- Step 2. Unplug and reconnect the USB cable.
- Step 3. Open it on the tablet (which adds the android_metadata table), and then close it.
- Step 3. Copy the SQLite database back to Windows.
- Step 4. Verify it using sqlite3.exe. It is NOT damaged.
Interestingly, if I switch steps 2 and 3, it also works.
Since it works, when I disconnect and reconnect the USB cable, I assume that I need to somehow reset the MTP cache. How can this be done or is there an API that I can use to quickly disconnect and reconnect the device?
My real Windows application uses the WPD (Windows Portable Devices) API, I just test with Windows Explorer to prove that this is not a problem in my Windows code. I do not see anything in WPD to make a flash.
The error occurs when the SQLite database on Android grows on a page (or more). SQLite's page size is 512 bytes. Looking at the binary data of the SQLite database, I can see what happens. I make the database one page larger on the device, copy the database from the device, disconnect the USB drive, connect it, and then copy it again. Comparing the two files, the file that I get after I copied the usb data remains the same, except that in the end it has a lot more data. He, like MTP, does not understand that the file is larger until you unplug the USB drive and plug it in again. If you leave the USB connected to it, only the number of bytes that was the last time it was copied is copied.
source share