Xamarin表单文件提供程序未设置 [英] Xamarin Forms File Provider not set

查看:95
本文介绍了Xamarin表单文件提供程序未设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习Xamarin.Forms的过程.我目前正在尝试使用Plugin.Media.CrossMedia库实现Camera功能.

I am currently going through the process of Learning Xamarin.Forms. I am currently attempting to implement Camera functions using the Plugin.Media.CrossMedia library.

在下面实现:

public async Task<ImageSource> StartCamera()
{
    await CrossMedia.Current.Initialize();


    if (Plugin.Media.CrossMedia.Current.IsTakePhotoSupported && CrossMedia.Current.IsCameraAvailable)
    {
            var photo = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions() { SaveToAlbum=false, SaveMetaData=false});

            if (photo != null)
                return ImageSource.FromStream(() => { return photo.GetStream(); });
            else
                return null;



    }
    else
    {
        return null;
    }
}

但是,在执行'TakePhotoAsync'方法时,我收到以下错误.

However upon executing the 'TakePhotoAsync' method I recieve the following error.

System.ArgumentException: Unable to get file location. This most likely means that the file provider information is not set in your Android Manifest file. Please check documentation on how to set this up in your project.

System.ArgumentException: Unable to get file location. This most likely means that the file provider information is not set in your Android Manifest file. Please check documentation on how to set this up in your project.

我尝试过查找,但无济于事.目前,我的AndroidManifest.xml文件是这样的.

I have tried looking this up but to no avail. My AndroidManifest.xml file looks like this at the moment.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="RCPTTracker.Android" android:versionCode="1" android:versionName="1.0">
    <uses-sdk />
    <application android:label="RCPTTracker.Android"></application>
</manifest>

我的含笑是,我需要在这里声明一些内容,但是我却找不到,我遵循的所有教程都没有设置文件提供程序.

My inkling is that I need to declare something in here, but I haven't been able to find what, and all tutorials i have followed don't go through anything with setting up a File Provider.

有什么建议吗?

推荐答案

自述文件说:

如果您的应用程序针对Android N(API 24)或更高版本,则必须使用2.6.0+版本.

If your application targets Android N (API 24) or newer, you must use version 2.6.0+.

您还必须添加一些其他配置文件以遵守新的严格模式:

You must also add a few additional configuration files to adhere to the new strict mode:

1.)将以下代码添加到您的AndroidManifest.xml标记内:

1.) Add the following to your AndroidManifest.xml inside the tags:

<provider android:name="android.support.v4.content.FileProvider" 
                android:authorities="YOUR_APP_PACKAGE_NAME.fileprovider" 
                android:exported="false" 
                android:grantUriPermissions="true">
                <meta-data android:name="android.support.FILE_PROVIDER_PATHS" 
                android:resource="@xml/file_paths"></meta-data>
</provider>

YOUR_APP_PACKAGE_NAME必须设置为您的应用包名称!

YOUR_APP_PACKAGE_NAME must be set to your app package name!

2.)将一个名为xml的新文件夹添加到您的Resources文件夹中,并添加一个名为file_paths.xml

2.) Add a new folder called xml into your Resources folder and add a new XML file called 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>

YOUR_APP_PACKAGE_NAME必须设置为您的应用包名称!

YOUR_APP_PACKAGE_NAME must be set to your app package name!

您可以在以下位置阅读更多信息: https://developer.android.com/training/camera/photobasics.html

You can read more at: https://developer.android.com/training/camera/photobasics.html

这篇关于Xamarin表单文件提供程序未设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆