probleme Datalogic memor 1 fichier csv n'est plus visible

Bonjour les amis,

j’ai développée une application sur un terminal memor1,
pais j’ain un petit probleme,

je genere un fichier .csv sur le terminal avec code C# xamarin forms
le fichier est generer avec succés
et je peux le voir dans le chemin de mon terminal
mais le problème lorsque je connecte le terminal sur poste Windows
et je dirige vers le chemin mon fichier n’est plus visible q’aprés redemarrage de terminal!!!
j’ai testé avec d’autre appareil et tous fonctionne bien et le fichier visible

svp de m’aider c’est top urgent,
bonne journée merci

Hello @RACHED_BKHAIRIA

Probably this is a well known bug of the Windows Driver for the Android MTP protocol, which doesn’t keep his internal database correctly synchronized with the Android File system changes. It works correctly with Linux machines but not with Ms Windows. The defect is already present with Android 4.4 devices

The possible workaround for an application that have to publish some files to be seen through Windows Explorer, is to manually force the Refresh of the MTP database.
On internet you can find several article on that topic.
The first that i found is:

http://tofu0913.blogspot.com/2014/01/force-android-mtp-database-refresh-if.html

Force Android MTP database refresh if file in storage changed
Method 1 .

Old method, not recommended.

sendBroadcast(**new** Intent(Intent.***ACTION_MEDIA_MOUNTED*** ,
Uri.parse(**"file://"** + Environment.getExternalStorageDirectory())));

Force whole SDCard rescan.
Side-effect: Some devices will force close or cause System UI exception.

Method 2.
Send intent to scan specific file, once it had been created.

Intent mediaScanIntent = **new** Intent(Intent.***ACTION_MEDIA_SCANNER_SCAN_FILE*** );
Uri contentUri = Uri.fromFile(file);
mediaScanIntent.setData(contentUri);
sendBroadcast(mediaScanIntent);

You need a for loop or recursive call if your target is a directory.

Method 3.
Similar with method 2, but do your Media scan by yourself.

public class MediaScanner implements MediaScannerConnectionClient {
private MediaScannerConnection mScanner ;
private File mFile ;

public MediaScanner(Context context, File file) {
   mFile = file;
   mScanner = new MediaScannerConnection(context, this );
   mScanner .connect();
}

@Override
public void onMediaScannerConnected() {
   mScanner .scanFile(mFile.getAbsolutePath(), null );
}

@Override
public void onScanCompleted(String path, Uri uri) {
   mScanner.disconnect();
}

public class YourClass {
   ...
   new MediaScanner(context, file);
   ...
}

Same as method 2, you need a ‘for’ loop or recursive call if your target is a directory.
Suggest to use Thread or ExecutorService for a better performance.

Some more info can be found also here:
https://developer.android.com/reference/android/media/MediaScannerConnection.html

Instead, if you need to “manually” resolve the issue, you have some options:

  1. you can reboot the device

  2. you can force a FileSystem Rescan by from setting menu:
    Go under setting > apps > (show system apps from the menu) > select Media Storage > Storage -> ClearData. This will force a rescan of the system.
    (see https://www.doubletwist.com/help/question/how-do-i-reset-the-android-media-scan-database/)

  3. download some apps from Google Play like:
    https://play.google.com/store/apps/details?id=com.house.noranuko.mediarescanner&hl=en
    https://play.google.com/store/apps/details?id=card.rescan.radeff&hl=it
    or many other

  4. use and ADB command as described here:
    https://android.stackexchange.com/questions/199685/manually-trigger-mediascanner-to-scan-files-on-internal-storage-on-nougat-oreo

Regards

Simone Callegari
Mobile Products L3 Specialist SW Engineer