If you’ve been doing any V2 extension development, you like are aware that we cannot use any .Net interop in our code.
While on premise V2 development will eventually gain access to .Net variable types, if you’re coding your extension to run in AppSource, you will remain locked away from using .Net interop in your code because the risk of these external components is too large for shared cloud servers.
Unfortunately this means that we lost the ability to interact with the device camera, as it was accessed using .Net.
In C/AL, the code to take a picture with the device camera looked like this:
TakeNewPicture() IF NOT CameraAvailable THEN EXIT; CameraOptions := CameraOptions.CameraOptions; CameraOptions.Quality := 50; CameraProvider.RequestPictureAsync(CameraOptions);
It’s simple enough code, but the problem in the above example is that both CameraProvider and CameraOptions are .Net variables, and therefore cannot be used in V2 extension development.
I’m happy to say though that this problem has been resolved. Yes, the underlying architecture still uses .Net controls, but Microsoft has introduced a new Camera Interaction page which acts basically like an api layer. Through this api layer you can interact with the .Net camera components just as you did in C/AL.
Not a huge change to wrap your head around at all. In your extension you will code against the Camera Interaction page instead of against the .Net controls directly. Inside the page are all the original camera functions that you were used to using before.
This greatly simplifies our extension code and allows us now to use the camera from our extensions.
The code to take a picture would now look like this:
local procedure TakePicture(); var CameraInteraction: Page "Camera Interaction"; PictureStream: InStream; begin CameraInteraction.AllowEdit(true); CameraInteraction.Quality(100); CameraInteraction.EncodingType('PNG'); CameraInteraction.RunModal; if(CameraInteraction.GetPicture(PictureStream)) then begin Picture.ImportStream(PictureStream, CameraInteraction.GetPictureName()); end; end;
That’s it! Now you can use the device camera from your V2 extensions.