How to save files into Specific folders in Android

Chinmay Dole 245 Reputation points
2024-07-26T13:21:47.3433333+00:00

I am working on migrating the Xamarin Forms App to .NET MAUI 8. I wanted to save files in the Android folder as given in the below Package for backward compatibility.

https://github.com/jamesmontemagno/MediaPlugin

User's image

How can I achieve this in Maui .NET 8?

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-07-29T03:25:08.9+00:00

    Hello,

    This package has been deprecated as it is legacy and is no longer maintained.

    Please see Xam.Plugin.Media's nuget package.

    If you want to pick or take a photo or video on the device. You can use MediaPicker in MAUI directly without install other packages.

    ==============Update================

    But for backward compatibility, I want to create these folders to show the saved local data.

    Ok, please find the AndroidManifest.xml, right-click it, choose Open with, select the source Code(Text) Editor.

    User's image

    Find the <Application> tag, add the <provider > information in it.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
    
    <application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true">
    
      <!--add here-->
    
        <provider android:name="androidx.core.content.FileProvider"        android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
    
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
    
        </provider>
    
    </application>
    
    
    <uses-permission android:name="android.permission.CAMERA" />
    </manifest>
    

    Then create a xml folder in the Platforms/Android/Resources, then create a xml file called file_paths.xml and make sure the buildaction is Androidresource

    enter image description here

    Copy following content to the file_paths.xml.

    <?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-files-path name="my_images" path="Pictures" />
    <external-files-path name="my_movies" path="Movies" />
    </paths>
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.