Introduction To Apache Cordova In Universal Windows Platform Using Visual Studio

Introduction

Apache Cordova (formerly PhoneGap) is a popular mobile application development framework. Apache Cordova is an open-source mobile development framework. Cordova is a platform which is used to build mobile apps, using HTML, CSS and JS. We can think of Cordova as a container to connect our Web app with the native mobile functionalities. Web Applications cannot use native mobile functionalities by default. This is where Cordova  comes in. It offers a bridge for the connection between the Web app and the mobile device.

Prerequisites
  • Visual Studio 2017 RC
Step 1

Click File--> select New--> select Project. The project needs to be clicked after opening all the types of projects in Visual Studio
or click (Ctrl+Shift+N).

 

Step 2

After opening the New Project, select Installed-->Templates-->JavaScript-->Mobile Apps-->choose the Blank app (Apache Cordova). Now, give your app; a name (Ex:sample) and give the path of your project. Afterwards, click OK.

 

Step 3

Now, go to Solution Explorer. In Solution Explorer, get all the files and sources in your project.

Subsequently, select Your Project-->www-->double click to open Index.html page. In this, the page is main view of your app. In this page, you can write HTML code.



Step 4

After opening index.html page, you can see the default HTML code. If you want, you can edit HTML code.



Step 5

Now, you can run your app. Choose, your platform on configuration manager, which shows the list of platform Android, iOS, Windows-ARM, Windows-x64 and Windows-x86.

 

Step 6

After choosing the platform, if you choose Windows, it shows the list Windows device, Local Machine and Emulators. If you want to run Windows Emulator, choose Windows 10 Emulator and run your app.

 

Output

After few seconds, the app will start running on your Emulator. You will see that Apache Cordova app works successfully.

 

Step 7

In this step, you want to edit your app. Delete the default HTML code and write the code, as per your desire.

 

Step 8

Now, you can write the code given below.

 

Index.HTML
  1. <!DOCTYPE html>  
  2. <html>  
  3.   
  4. <head>  
  5.     <!--  
  6. Customize the content security policy in the meta tag below as needed. Add 'unsafe-inline' to default-src to enable inline JavaScript.  
  7. For details, see http://go.microsoft.com/fwlink/?LinkID=617521  
  8. -->  
  9.     <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">  
  10.     <meta http-equiv="content-type" content="text/html; charset=UTF-8" />  
  11.     <meta name="format-detection" content="telephone=no">  
  12.     <meta name="msapplication-tap-highlight" content="no">  
  13.     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">  
  14.     <link rel="stylesheet" type="text/css" href="css/index.css">  
  15.     <title>ApacheCordovaUWP</title>  
  16. </head>  
  17.   
  18. <body>  
  19.     <h1>Hello UWP</h1>  
  20. </body>  
  21.   
  22. </html>  
Output

After running your app, see your HTML code works successfully.

 

Step 9

In this step, write CSS code in your app. Go to Solution Explorer-->your app-->www-->css--> select index.css file.



Step 10

After opening the index.css file, see the default CSS code. You can write CSS code here.

 

Step 11

In this step, go to Index.html page and write HTML code given below.



Index.html
  1. <!DOCTYPE html>  
  2. <html>  
  3.   
  4. <head>  
  5.     <!--  
  6. Customize the content security policy in the meta tag below as needed. Add 'unsafe-inline' to default-src to enable inline JavaScript.  
  7. For details, see http://go.microsoft.com/fwlink/?LinkID=617521  
  8. -->  
  9.     <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">  
  10.     <meta http-equiv="content-type" content="text/html; charset=UTF-8" />  
  11.     <meta name="format-detection" content="telephone=no">  
  12.     <meta name="msapplication-tap-highlight" content="no">  
  13.     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">  
  14.     <link rel="stylesheet" type="text/css" href="css/index.css">  
  15.     <title>ApacheCordovaUWP</title>  
  16. </head>  
  17.   
  18. <body>  
  19.     <h1>Hello UWP</h1> <button id="button1">Click</button> </body>  
  20.   
  21. </html>  
Step 12

In this step, go to the index.css page. Write CSS code given below.

 

Index.css
  1. #button1 {  
  2.     margin - left: 150 px;  
  3.     background - color: aqua;  
  4.     color: black;  
  5. }#button1: hover {  
  6.     background - color: red;  
  7.     color: white;  
  8. }  
Output

After running your app, see that your HTML and CSS work successfully.







Summary

Thus, this was the introduction to Apache Cordova in Universal Windows Platform, using Visual Studio.


Similar Articles