简体   繁体   English

在xamarin.android/iOS中检查相机是否正常工作

[英]Check camera working or not in xamarin.android/iOS

I am developing app for Android/iOS in which we have implemented camera functionality. 我正在为Android / iOS开发应用程序,其中已实现了相机功能。

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. 该应用将在Android / iOS平台上可用。

Can we do this by code in xamarin OR there is other workaround available ? 我们可以通过xamarin中的代码来执行此操作吗?还是可以使用其他解决方法?

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. 您可以使用xam.plugin.media的nuget中的xam.plugin.media。 add this package to your Android and IOS projects too. 将此包也添加到您的Android和IOS项目中。 Read this link for more information about permissions and configurations jamesmontemagno/MediaPlugin 阅读此链接以获取有关权限和配置的更多信息jamesmontemagno / MediaPlugin

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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