简体   繁体   中英

Check camera working or not in xamarin.android/iOS

I am developing app for Android/iOS in which we have implemented camera functionality.

This functionality includes whenever user clicks a photo of particular object we are calculating some values by processing the image. This functionality is working fine as of now.

However one more validation we need to add is if user tries to take the picture and if camera is not working/blocked then we need to show some alert saying camera not available.

This app is going to available in Android/iOS platforms.

Can we do this by code in xamarin OR there is other workaround available ?

I tried with few camera enable/disable apps, but in that case the alert is not showing, it only closes our app.

Any help on this appreciated !

You can use xam.plugin.media from nuget by jamesmontemagno. add this package to your Android and IOS projects too. Read this link for more information about permissions and configurations jamesmontemagno/MediaPlugin

if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
  {
      await DisplayAlert("Error", "No camera available.", "Dismiss");
      return;
  }

CrossMedia is in using Plugin.Media; namespace. using Plugin.Media; namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM