Maximum Mobility: Listing 2.

JavaScript file for camera interaction.

var pictureSource;   // Picture source
var destinationType; // Sets the format of returned value 

// Wait for PhoneGap to connect with the device
document.addEventListener("deviceready", onDeviceReady, false);

// PhoneGap is ready to be used!
function onDeviceReady() {
  pictureSource =;
  destinationType =;

// Called when a photo is successfully retrieved
function onPhotoDataSuccess(imageData) {
  var capturedPhoto = document.getElementById('capturedPhoto'); = 'block';
  capturedPhoto.src = imageData;
  navigator.notification.alert("Picture Successfully Captured!");    

// Called when a photo is successfully retrieved
function onPhotoURISuccess(imageURI) {
  var selectedFromPhotoLibrary = document.getElementById('selectedFromPhotoLibrary'); = 'block';
  selectedFromPhotoLibrary.src = imageURI;
  navigator.notification.alert("Picture Imported Captured!");

function capturePhoto() {
  // Take picture using device camera and retrieve image, onFail, { quality: 50 });

// A button will call this function
function getPhoto(source) {
  // Retrieve image file location from specified source, onFail, { quality: 50,
    destinationType: destinationType.FILE_URI,
    sourceType: source
// Error Handling
function onFail(message) {
    alert('Failed because: ' + message);

About the Author

Michael Crump is a product manager that works at Microsoft on the Azure platform. He is a is a developer, blogger and speaker of topics relating to cloud development. He’s passionate about helping developers understand the benefits of the cloud in a no-nonsense way. You can reach him on Twitter at mbcrump or by following his blog at

comments powered by Disqus


  • Move Over, Stack Overflow: Microsoft Launches Q&A for .NET

    Stack Overflow probably isn't worried, but Microsoft has launched its own Q&A site for all things .NET, seeking to provide a one-stop-shop for getting .NET technical questions answered by the community.

  • Developer Decries WinForms-to-Blazor Performance Degradation

    Since shipping .NET 5, Visual Studio 2019 v16.8 and more goodies recently, Microsoft has been touting speed improvements in many components -- including the red-hot Blazor project -- but some real-world developers are finding different results.

  • Google Cloud Functions Supports .NET Core 3.1 (but not .NET 5)

    Google Cloud Functions -- often used for serverless, event-driven projects -- now supports .NET, but the new support is a release behind Microsoft's latest .NET offering.

  • Binary Classification Using PyTorch: Model Accuracy

    In the final article of a four-part series on binary classification using PyTorch, Dr. James McCaffrey of Microsoft Research shows how to evaluate the accuracy of a trained model, save a model to file, and use a model to make predictions.

  • Visual Basic in .NET 5: Ready for WinForms Apps

    With the milestone .NET 5 and Visual Studio 2019 v16.8 releases now out, Microsoft is reminding Visual Basic coders that their favorite programming language enjoys full support and the troublesome Windows Forms Designer is even complete -- almost.

Upcoming Events