Error Xamarin Forms MediaPlugin

0

Friends I have this problem that I can not use the camera with Xamarin Forms , I have problems with the perismos, I am guiding myself on this reference link

and it asks me to create a folder xml where I add the file file_paths.xml , but when I try to run it and send me the following error

  

Error 12: error: Error: No resource found that matches the given name (at 'resource' with value '@ xml / file_paths'). PhotoCam.Android C: \ Users \ erpre \ Source \ Repos \ PhotoCam \ PhotoCam \ PhotoCam.Android \ obj \ Debug \ android \ manifest \ AndroidManifest.xml

private async void TmPic(object sender, EventArgs e) {
  await CrossMedia.Current.Initialize();
  if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) {
    await DisplayAlert("Error", ":c Cámara no disponible.", "Continuar");
    return;
  } else {
    var file = await CrossMedia.Current.TakePhotoAsync(
      new StoreCameraMediaOptions {
        Directory = "Images",
          Name = DateTime.Now + "_img.jpg"
      });

    if (file == null) {
      return;
      myImg.Source = ImageSource.FromStream(() => file.GetStream());
    }

  }


}

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>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.PhotoCam" android:installLocation="auto">
  <uses-sdk android:minSdkVersion="12" android:targetSdkVersion="25" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.CAMERA" />
  <application android:label="PhotoCam.Android" android:icon="@drawable/icon">
    <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.PhotoCam.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>
</manifest>
    
asked by E.Rawrdríguez.Ophanim 13.04.2018 в 01:14
source

1 answer

1

The error that is giving you is because Android does not know that it has the file file_paths either because it is not correct or it is not correctly added.

First, click with the right button on the file and select properties, make sure that the first option (Build Action) is AndroidResource and in filename make sure it is fine file_paths.xml

Then make sure that the content is something like this:

<?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>

Especially the first and second lines.

In the AndroidManifest.xml file (which is inside Properties in the Android project)

you must have something like this:

<application android:label="Nombre de la app" android:icon="@drawable/icon">
        <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.XXXX.YYYY.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>

com.XXXX.YYYY should be the name of the apk that is typically com.company.project

Then clean the solution and recompile it.

    
answered by 13.04.2018 / 12:21
source