Click here to Skip to main content
12,396,230 members (72,515 online)
Click here to Skip to main content


42 bookmarked

Android and iOS Mobile Device Development with Azure Mobile Services using HTML5 and JavaScript

, 10 May 2013 CPOL
Tutorial showing how to build an iOS or Android app using Azure Mobile Services with HTML5 and JavaScript in Visual Studio.
<!DOCTYPE html>
        <title>Todo list: bjrtodolist</title>
        <link rel='stylesheet' href='style/styles.css' />
        <!--[if lt IE 9]><script src="//"></script><![endif]-->
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <div id='wrapper'>
                    <h2>Windows Azure</h2>
                    <h1>Mobile Services</h1>

                    <form id='add-item'>
                        <button type='submit'>Add</button>
                        <div><input type='text' id='new-item-text' placeholder='Enter new task' /></div>

                <ul id='todo-items'></ul>
                <p id='summary'>Loading...</p>

                <a href=''>
                    Learn more about Windows Azure Mobile Services

        <script src='scripts/jquery-1.9.1.min.js'></script>
        <script src='scripts/MobileServices.Web-1.0.0.min.js'></script>
        <script src='scripts/app.js'></script>

<!--<!DOCTYPE html>
    <title>Page Title</title>
    <script src="scripts/jquery-1.6.4.js" type="text/javascript"></script>
    <script src="scripts/" type="text/javascript"></script>
    <script src="scripts/cordova.js" type="text/javascript"></script>
    <link rel="Stylesheet" href="style/" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
        <div data-role="page" id="page1">
            <div data-theme="e" data-role="header">
            <div data-role="content">
                        This is your Nomad project...
                <ul data-role="listview" data-divider-theme="e" data-inset="true">
                    <li data-role="list-divider" role="heading">
                        Getting Started
                    <li data-theme="c">
                        <a href="" target="_newtab">
                            Read the guide
                    <li data-theme="c">
                        <a href="" target="_newtab">
                            Report a problem
                    <li data-theme="c">
                        Hit the build button and try it on a device!

                <hr />

                <ul data-role="listview" data-divider-theme="e">
                    <li data-role="list-divider" role="heading">
                        Device Information
                        <h3>Compass heading: <span id="heading">n/a</span></h3>
                        <p>Uses compass.watchHeading</p>
                        <h3>Connection type: <span id="connection">n/a</span></h3>
                        <p>Uses connection.type</p>
                    <li data-theme="c">
                        <h3>Contacts: <span id="contacts">n/a</span></h3>
                        <p>Uses navigator.contacts.find</p>
                    <li data-theme="c">
                        <h3>Device properties:</h3>
                        <p>Uses device.*</p>
                        <div id="deviceprops" style="font-size: 11px;">n/a</div>
                    <li data-theme="c">
                        <h3>Geolocation: <span id="geolocation">n/a</span></h3>
                        <p>Uses navigator.geolocation.watchPosition</p>
                    <li data-theme="c">
                        <img alt="" src="images/choosephoto.png" id="picture" /><button data-role="button" data-inline="true" onclick="showPictures();">
                            Choose a picture
                        <p><span id="geolocationerror"></span></p>
            <div data-theme="a" data-role="footer">

            <script type="text/javascript">
                function showPictures() {
           (imageURI) {
                        $('img#picture').attr('src', imageURI);
                    }, function (error) {
                        $('img#picture').replaceWith('<p>' + error + '</p>');
                    }, { sourceType:, destinationType: });

                $(function () {
                    var compassWatchID, geoWatchID;

                    document.addEventListener("deviceready", function () {
                        // Compass
                        compassWatchID = navigator.compass.watchHeading(function (heading) {
                            $('span#heading').html(heading.magneticHeading.toFixed(2) + '&#176;');
                        }, function (error) {
                        }, { frequency: 3000 });

                        // Connection
                        var networkState =,
                            states = {};

                        states[Connection.UNKNOWN] = 'Unknown';
                        states[Connection.ETHERNET] = 'Ethernet';
                        states[Connection.WIFI] = 'WiFi';
                        states[Connection.CELL_2G] = 'Cell 2G';
                        states[Connection.CELL_3G] = 'Cell 3G';
                        states[Connection.CELL_4G] = 'Cell 4G';
                        states[Connection.NONE] = 'No network';


                        // Contacts
                        navigator.contacts.find(['id'], function (contacts) {
                            $('span#contacts').text(contacts.length + ' found');
                        }, function (error) {
                        }, { multiple: true });

                        // Device properties
                            '<strong>Name:</strong> ' + + '<br/>' +
                            '<strong>Cordova version:</strong> ' + device.cordova + '<br/>' +
                            '<strong>Platform:</strong> ' + device.platform + '<br/>' +
                            '<strong>UUID:</strong> ' + device.uuid + '<br/>' +
                            '<strong>Version:</strong> ' + device.version + '<br/>'

                        // Geolocation
                        geoWatchID = navigator.geolocation.watchPosition(function (position) {
                            $('span#geolocation').text(position.coords.latitude.toFixed(2) + 'N, ' + position.coords.longitude.toFixed(2) + 'E');
                        }, function (error) {
                            $('span#geolocationerror').text(error.code + ': ' + error.message);
                        }, { frequency: 3000 });
                } ());

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Bart Read
Team Leader Red Gate Software
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 10 May 2013
Article Copyright 2013 by Bart Read
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid