0

I'm trying to sync some txt files from Android with my PC, but it seems that not the entire information held in the file is sync-ed.

After researching, I've found out some possible answers on: Android How to use MediaScannerConnection scanFile and MediaScannerConnection produces android.app.ServiceConnectionLeaked.

But after implementing something similar to what is described there:

 Intent mediaSessionFilesScannerIntent = new Intent(Intent.ActionMediaScannerScanFile);
            Intent mediaDailyFilesScannerIntent = new Intent(Intent.ActionMediaScannerScanFile);

            Android.Net.Uri fileContentSessionUri = Android.Net.Uri.FromFile(new File(sessionFilePath));
            Android.Net.Uri fileContentDailyUri = Android.Net.Uri.FromFile(dailyLogsFile);

            mediaSessionFilesScannerIntent.SetData(fileContentSessionUri);
            Application.Context.SendBroadcast(mediaSessionFilesScannerIntent);

            mediaDailyFilesScannerIntent.SetData(fileContentDailyUri);
            Application.Context.SendBroadcast(mediaDailyFilesScannerIntent);

I've observed that even altought the items seems to be in sync on PC and Android file system (when creating a new file it appears also on PC), the sizes of them on the 2 devices are different. The above code is called everytime after something is written in those files, but the sync between the actual contents of the files from Android and the ones appearing on PC does not seem to happen.

Any idea how can my problem be solved?

Later edit: I am using a Bluebird device

D.Andrei
  • 35
  • 7
  • when you sync TXT file at the first time, this TXT file was created, Is this file blank ? Or the first time is normal, but in next time, this files cannot be synchronized. When you run your app in Android simulator, did you get some errors or warrings in logcat? – Leon Jan 21 '19 at 02:57
  • The first time I create the txt file, also contains a line. Later in the app, I am continuing to add lines to that TXT and always using Media Scanner Connection to run an intent for ActionMediaScannerScanFile. What is happening is that the file appears on PC, but is smaller than the one from Android device. I tought that Media Scanner Connection's purpose is to sync files when a device is connectat via usb to PC, so in my mind also the content of the file should be synced, but I am not 100% sure about this. – D.Andrei Jan 21 '19 at 08:10

0 Answers0