0

I'm not sure, if it's the right question for SO, but since it's programming-related, I put it here. I'm developing a UI application for Android. The app creates some files in external memory.

I tried to backup those files on my PC. I plugged in the device and didn't even find my application's directory. It was there in my phone's file explorer, though. Replugging didn't work. It can be solved by altering some file using phone manually, e.g. change some file's name, create a new directory. This refreshes the whole thing. As a result my computer's file explorer lags for a while and displays files. It seems as if files were buffered into PC and my app didn't have permission to order a rebuffer after its IO.

It's not just some displaying problem, those files really stay unchanged after my application's work. I generated different results in my app, so it would overwrite the old files. In device's explorer I saw the latest files, but on desktop I got the old ones (even after copying them to hard drive).

My desktop is Windows 7 64bit, my phone is Huawei Honor 4X, I use the original cable. My previous phone was Galaxy Core Plus and I didn't encounter this problem (with same app). I think Huawei's rom might be a little buggy. After I'd deleted some file through desktop, it was still shown in phone's file manager.

Is it possible to somehow ,,refresh" this connection programatically, so it would show up-to-date results on any device?

Maciej Dziuban
  • 474
  • 3
  • 21

1 Answers1

0

You can implement this function for your needs:

void MakeFileAvailable (Context context, File file)
{
    MediaScannerConnection.scanFile(context,
            new String[] { file.toString() }, null,
            new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri){
                    Log.d(TAG, "File scanned" + path);
                }
            });

}

In the context argument you have to put a context of your activity. You can get your context in your activity class with function 'getBaseContext()'.

Dainius Šaltenis
  • 1,644
  • 16
  • 29