{"id":1122,"date":"2018-04-05T13:14:12","date_gmt":"2018-04-05T13:14:12","guid":{"rendered":"http:\/\/sezeromer.com\/?p=1122"},"modified":"2023-02-26T13:48:18","modified_gmt":"2023-02-26T10:48:18","slug":"xamarin-forms-kamera-islemleri-guncelleme","status":"publish","type":"post","link":"https:\/\/sezeromer.com\/en\/xamarin-forms-kamera-islemleri-guncelleme\/","title":{"rendered":"Xamarin Forms Camera ( Media.Plugin )"},"content":{"rendered":"<p>I will talk to you about the solution of a mistake I have often taken in this writing recently. Especially recently, we had to give a few more details to include the Media.Plugin, which we used in Xamarin Forms to shoot videos and photos, into the project. If I did not make these settings, my error was as follows.<\/p>\n<p><em>\u201c<strong><code>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.<\/code><\/strong>\u201c<\/em><\/p>\n<p>To avoid such an error, follow the steps below. First, we need to install <strong>Media.Plugin<\/strong> with the Manage Nuget Package Manager. After installing this package, we are confronted with a file named readme.txt. After installing the package we need to allow a couple of androids. These permissions will use the camera, read the memory, and write data to the memory. To do this, we have to go to the android layer of our project and click on the right and click on the properties option. There are options on the side of the page. We come to the Android Manifest layer from these options. The permissions granted on this page must be given on the spot above. So we can use these features that we allow.<\/p>\n<p>After completing the first step, we have to take another step, the permissions we give in the Main Activity class. For this you need to copy and paste the following code snippet there.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults)\r\n{\r\n    Plugin.Permissions.PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);\r\n}<\/pre>\n<\/div>\n<p>After passing this step, if the package that we added the other step does not come automatically in the Main Activity class, we need to manually add it. Again, we need to do this with the code snippet below.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;<\/pre>\n<\/div>\n<p>After that, you need to do a few more steps afterwards. We will also add the following line of code to the AssemblyInfo.cs class, which is located under the android layer.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">[assembly: UsesFeature(\"android.hardware.camera\", Required = false)] \r\n[assembly: UsesFeature(\"android.hardware.camera.autofocus\", Required = false)]<\/pre>\n<\/div>\n<p>Finally, we came up with the most critical thing to do. With this last step, we specify which file path we will store our data in. If we can not do it correctly, we get the error I mentioned at the beginning of the article. We will make a few additions to the AndroidManifest.xml file inside the properties under the Android layer. You need to add the following code snippet inside the application tags contained in this file.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">&lt;provider android:name=\"android.support.v4.content.FileProvider\" \r\n          android:authorities=\"${applicationId}.fileprovider\" \r\n          android:exported=\"false\" \r\n          android:grantUriPermissions=\"true\"&gt;\r\n          \r\n\t  &lt;meta-data android:name=\"android.support.FILE_PROVIDER_PATHS\" \r\n                     android:resource=\"@xml\/file_paths\"&gt;&lt;\/meta-data&gt;\r\n&lt;\/provider&gt;<\/pre>\n<\/div>\n<p>Lastly, we need to open an xml file to tell the phone what path our files are on. We create this xml file in the Resources folder at the bottom of the Android layer by creating an xml named folder and then creating a file named file_paths.xml into it and importing it into the code below.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;paths xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\r\n    &lt;external-files-path name=\"my_images\" path=\"Pictures\" \/&gt;\r\n    &lt;external-files-path name=\"my_movies\" path=\"Movies\" \/&gt;\r\n&lt;\/paths&gt;<\/pre>\n<\/div>\n<p>You can easily use <strong>Xaml.Media.Plugin<\/strong> after this process.<\/p>\n<p>You can save the photo <a href=\"http:\/\/sezeromer.com\/xamarin-forms-kamera-islemleri\/\">here<\/a>, for taking pictures, selecting or taking a video.<\/p>\n<p>If you have any questions, you can reach us by email or comment.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>I will talk to you about the solution of a mistake I have often taken in this writing recently. Especially recently, we had to give a few more details to include the Media.Plugin, which we used in Xamarin Forms to shoot videos and photos, into the project. If I did not make these settings, my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":353,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[289,288,3],"tags":[114,159,377,295,115,158,376,7,22,375],"class_list":["post-1122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","category-ios","category-xamarin-ile-yapilmis-projeler","tag-android","tag-camera","tag-file-paths","tag-hata","tag-ios","tag-kamera","tag-media","tag-omer-sezer","tag-xamarin","tag-xaml-media-plugin"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1122"}],"collection":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/comments?post=1122"}],"version-history":[{"count":4,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1122\/revisions"}],"predecessor-version":[{"id":2584,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1122\/revisions\/2584"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media\/353"}],"wp:attachment":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media?parent=1122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/categories?post=1122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/tags?post=1122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}