Forum Xamarin.Forms

How to get data files folder in Xamarin.Forms

jstuardojstuardo Member ✭✭

Hello,

I need to show a video file in Xamarin.Forms. I have placed the MP4 file in \Internal storage\Android\data\com.mycompany.MyApp\files\Videos

Then, I tried to access it using:

string videoPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), this.viewModel.Item.Video)

But videoPath variable contains "/data/data/com.desytec.FinningApp/files/Videos/777.mp4" .

Then, I am checking file existence:

bool existing = System.IO.File.Exists(videoPath);

But "existing" returns false. I tried by changing the first "/data" to "/Android" but the file is not found either.

Any help, please?

Thanks
Jaime

Best Answers

Answers

  • jstuardojstuardo Member ✭✭

    Hello,

    I have read documents but I have one question. You tell me that in my case, this is the External storage, but the device does not have an external media, and in fact, when browsing using my PC, it is named as "Internal storage":

    Please look at this screenshot:

    The path that is shown is:

    "Este equipo\C4050-Q4\Almacenamiento interno\Android\data\com.company.MyApp"

    the path means:

    "This PC\C4050-Q4\Internal storage\Android\data\com.company.MyApp"

    When browsing the folder using the device, this is shown:

    As you see, that is Internal storage, however, I can browse using the PC, create folders and save files in there. Is it something I can do to access that folder using the app? by the way, I have seen that inside "files" folder are other called ".override" which contains the DLL's files generated by Visual Studio when deployed the app.
    .
    On the other hand, the document says that internal storage have the format: /data/user/0/com.companyname/files, however, the path gotten by the method call is /data/data/com.companyname.MyApp/files. Are they actually the same?

    To test, I tried by hardcoding the full path "/Device storage/Android/data/com.desytec.FinningApp/files/Videos/777.mp4" but when using System.IO.File.Exists method call, false is returned, even when I can see the file is there.

    Any further help to solve above questions, please?

    Regards

    Jaime

  • jstuardojstuardo Member ✭✭

    Hello,

    Finally I understood that external storage does not mean necessarily an external media. I tried by getting the folder this way:

    System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryMovies)

    Then I copied the video to the Movies folder, and it worked!

    Regards
    Jaime

  • jstuardojstuardo Member ✭✭
    edited July 2019

    Thanks @LandLu,

    Finally, I could do it the way you suggested. I need to implement a dependency service to get the path according to platform.

    What is the equivalence of Android.OS.Environment.ExternalStorageDirectory.AbsolutePath in iOS?

    Regards
    Jaime

  • LandLuLandLu Member, Xamarin Team Xamurai

    @jstuardo iOS has a different file system. Each app on iOS has its own sandbox storage: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html.
    Generally, we store user's data in the Documents folder. And we could access its path on Forms directly:

    var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    
  • Glorious18Glorious18 Member ✭✭✭

    Hin Landlu
    Please I need help if possible

    PROBLEM:
    I designed an app that I published in the google play store
    The app uses a Local database (SQlite) to enable the user to register once and use the app for a limited period of 1 year only.
    But...
    the problem is that when a user installs my app, he can easily go to the settings of his Android phone, click on Apps
    then look for the installed app
    and click on Storage

    and
    Clear All Data
    stored in the local database

    by doing so, he will be able to use it again as if it is the first time.

    So the trial period is useless in this case

    NEED:
    Is there a sample project (simple) to show how to store and retrieve data in a public file outside the application storage location so that a user does not and is not capable of deleting when he clears all data and clear the cache of the app?

    I want the user to be given a period of 1 month to use my app and the first date of usage is needed to be stored in the phone but without being able to deleted when the data stored in the app is clicked in the settings

Sign In or Register to comment.