0

When i Want to Open camera When Activity is Started is see This Exception

Android.OS.FileUriExposedException

This is My Code

        var CameraIntent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
        var activities = PackageManager.QueryIntentActivities(CameraIntent, 0);
        if (activities.Count > 0)
        {
            Java.IO.File ImageFile = new Java.IO.File(FriendRepository.GetImage(friend.FriendID));
            Android.Net.Uri ImageUri = Android.Net.Uri.FromFile(ImageFile);
            CameraIntent.PutExtra(MediaStore.ExtraSizeLimit, 1024);
            CameraIntent.PutExtra(MediaStore.ExtraOutput, ImageUri);
            StartActivityForResult(CameraIntent,0);
        } else {
            Toast.MakeText(this, "دوربین یافت نشد لطفا دوباره امتحان کنید.", ToastLength.Long).Show();
        }
Sham Dhiman
  • 1,348
  • 1
  • 21
  • 59
hamid
  • 1
  • 3
  • You have to grant read uri permission to your intent, as shown here https://stackoverflow.com/a/38858040/11104068 – Saamer Dec 26 '19 at 15:16
  • Which line of the code causes the error? What is the details of FileUriExposedException? You could check the link, it would be helpful.https://medium.com/@ali.muzaffar/what-is-android-os-fileuriexposedexception-and-what-you-can-do-about-it-70b9eb17c6d0 – Wendy Zang - MSFT Dec 27 '19 at 07:07

0 Answers0