Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Phonegap for Android

553 views

Published on

Dr. Ramkumar Lakshminarayanan article published in Tamil Computer Magazine. The content is about phonegap to create Android Application.

Published in: Mobile
  • Be the first to comment

Phonegap for Android

  1. 1. ç«ð£¡«èŠ Íô‹ ݇† 󣌴 ÜŠO«èê¡ à¼ õ£‚è º®»‹. Þ‰î ç«ð£¡ «èŠèœ ðô ãHäè¬÷ Ýî K‚A¡øù. ܬõ Accelerome ter, Camera, Capture, Compass, Connection, Contacts, Device, Events, File, Geolocation, Media, Notifi cation, Storage «ð£¡ ø¬õò£°‹. ÜŠO«èê¡ GÁõŠð† ´œ÷ ®¬õC¡ îèõ¬ô ªðÁõ ®¬õv ãHä ðò¡ð´Aø¶. ®¬õv ãHä J¡ Šó£Šð˜†¯v Device Name, Device Cordova, Device Platform, Device uuid, Device Version «ð£¡ø¬õ ò£°‹. ®¬õv ãHäJ¬ù ðò¡ 𴈶õ W›õ¼‹ è†ì ¬÷è¬÷ õöƒè «õ‡´‹. app/xme/plugins.xml-L™ <pluginname="Device"Value" org.apache cordova. Device"/> â¡Á ܬñ‚è «õ‡´‹. ܶ«ð£ô app/Android.Mani fest.xml ç¬ðL™, < u s e s - p e r m i s s i o n android=name= "android.permission READ-PHONE-STATE"/> â¡Á ªè£´‚è «õ‡´‹. ®¬õv ãHä ðò¡ð´ˆ¶ õîŸè£ù Gó™-1™ ªè£´‚èŠ ð†´œ÷¶. Þ‰î âO¬ñ ò£ù Gó™ ðì‹-1™ àœ÷¶ «ð£¡Á «î£¡Á‹. «èŠê˜ ãHä Íô‹ Ý®«ò£, Þ«ñx ñŸÁ‹ i®«ò£ «èŠê˜ ªêŒòô£‹. «èŠê˜ ãHä ðò¡ð´ˆ¶ ç«ð£¡«èŠH™ ݇†ó£Œ¬ì à¼õ£‚èô£‹! õîŸè£ù Plugins.xml ñŸÁ‹ Android Mainfest.xml L™ W› è‡ì Gó™è¬÷ ܬñˆ Fì «õ‡´‹. app/res/xml/plugins.xml- è£ù Gó™ <Plugin name="capture" value="org.apache.cordova. cap ture"/> app/AndroidManifest/xml- è£ù GóL™ Permission õöƒAì «õ‡´‹. < u s e s - p e r m i s s i o n android:name= "android.permission.RECOR D_AUDIO"/> < u s e s - p e r m i s s i o n android:name= "android.permission.WRITE _ E X T E R N A L _ S T O R A G E " > «èŠê˜ ªêòL¬ù Gó™-2™ ªè£´‚èŠð†´œ÷¶. «èŠê˜ Ý®«ò£ â¡ø ð†ì¬ù AO‚ ªêŒî¾ì¡ ðì‹-2™ àœ÷¶ «ð£¡Á F¬ó «î£¡Á‹. Þî¬ù ªê™«ðCJ™ GÁ¾õî¡ Íô‹ «èŠê˜ ªêòL¬ù ªêò™ð´ˆîô£‹. Ü´ˆî¶v«ì£«óxãHä ðò¡ð´ˆ¶‹ º¬ø. ݇† 󣌴 ÜŠO«èê¡ èœ îè õ™è¬÷ âv‚άô† «ì†ì£«ðC™ «êI‚èô£‹. app/res/xml/plugins.xml- L™ H÷‚-Þ¡ GóL¬ù Þ¬í‚è «õ‡´‹. <plugin name="storage" value = "org.apache. cordova. storage"/>â¡ðî¬ù ªè£´ ‚è «õ‡´‹. «ì†ì£«ðv ðò¡ð´ˆ¶ õîŸè£ù Gó™-3™ ªè£´‚ èŠð†´œ÷¶. Ü´ˆîî£è èªù‚û¡ ÜPõîŸè£ù ãHä ÜŠO«è ê¡ «ð£¡ø ªêò™è¬÷ ªêŒ õ ªï†å˜‚ èªù‚û¡ ÜõCòñ£ù‹. Plugins.xml-™ W›è‡ì Gó™è¬÷ ªè£´‚è «õ‡ ´‹. <Plugin name="Network status" ðì‹-1 ðì‹-2 ðì‹-3
  2. 2. Ý¡†ó£Œ´ -2 Þ󣋰ñ£˜ ªô†²Iï£ó£òí¡ 25 <!DOCTYPE html> <html> <head> <title>Device Properties Example</title> <script type="text/javascript" charset="utf- 8" src="cordova-2.0.0.js"></script> <script type="text/javascript" charset="utf- 8"> // Wait for Cordova to load // document.addEventListener("deviceready", onDeviceReady, false); // Cordova is ready // function onDeviceReady() { var element = document.getElementById('deviceProperties'); element.innerHTML = 'Device Name: ' + device.name + '<br />' + 'Device Cordova: ' + device.cordova + '<br />' + 'Device Platform: ' + device.platform + '<br />' + 'Device UUID: ' + device.uuid + '<br />' + 'Device Version: ' + device.version + '<br />'; } </script> </head> <body> <p id="deviceProperties">Loading device properties...</p> </body> </html> value= "org.apche.cordova. Network Mana ger"/> H¡¹ app/AndroidMani fast.xml -™ <uses-permission android: name="android. permission. ACCESS-NETWORK-STATE">/ Gó™-1 Gó™-2 application, // allowing user to capture up to 2 audio clips navigator.device.capture.captureAudio(capture Success, captureError, {limit: 2}); } // Upload files to server function uploadFile(mediaFile) { var ft = new FileTransfer(), path = mediaFile.fullPath, name = mediaFile.name; ft.upload(path, "http://my.domain.com/upload.php", function(result) { console.log('Upload success: ' + result.responseCode); console.log(result.bytesSent + ' bytes sent'); }, function(error) { console.log('Error uploading file ' + path + ': ' + error.code); }, { fileName: name }); } </script> </head> <body> <button onclick="captureAudio();">Capture Audio</button> <br> </body> </html> <!DOCTYPE html> <html> <head> <title>Capture Audio</title> <script type="text/javascript" charset="utf-8" src="cordova- 2.0.0.js"></script> <script type="text/javascript" charset="utf-8" src="json2.js"></script> <script type="text/javascript" charset="utf-8"> // Called when capture operation is finished // function captureSuccess(mediaFiles) { var i, len; for (i = 0, len = mediaFiles.length; i < len; i += 1) { uploadFile(mediaFiles[i]); } } // Called if something bad happens. // function captureError(error) { var msg = 'An error occurred during capture: ' + error.code; navigator.notification.alert(msg, null, 'Uh oh!'); } // A button will call this function // function captureAudio() { // Launch device audio recording
  3. 3. <!DOCTYPE html> <html> <head> <title>Storage Example</title> <script type="text/javascript" charset="utf- 8" src="cordova-2.0.0.js"></script> <script type="text/javascript" charset="utf- 8"> // Wait for Cordova to load // document.addEventListener("deviceready", onDeviceReady, false); // Cordova is ready // function onDeviceReady() { var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000); db.transaction(populateDB, errorCB, successCB); } // Populate the database // function populateDB(tx) { tx.executeSql('DROP TABLE IF EXISTS DEMO'); tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)'); tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")'); tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")'); } // Transaction error callback // function errorCB(tx, err) { alert("Error processing SQL: "+err); } // Transaction success callback // function successCB() { alert("success!"); } </script> </head> <body> <h1>Example</h1> <p>Database</p> </body> </html>] <!DOCTYPE html> <html> <head> <title>navigator.network.connection.type Example</title> <script type="text/javascript" charset="utf-8" src="cordova- 2.0.0.js"></script> <script type="text/javascript" charset="utf-8"> // Wait for Cordova to load // document.addEventListener("deviceready", onDeviceReady, false); // Cordova is loaded and it is now safe to make calls Cordova methods // function onDeviceReady() { checkConnection(); } function checkConnection() { var networkState = navigator.network.connection.type; var states = {}; states[Connection.UNKNOWN] = 'Unknown connection'; states[Connection.ETHERNET] = 'Ethernet connection'; states[Connection.WIFI] = 'WiFi connection'; states[Connection.CELL_2G] = 'Cell 2G connection'; states[Connection.CELL_3G] = 'Cell 3G connection'; states[Connection.CELL_4G] = 'Cell 4G connection'; states[Connection.NONE] = 'No network connection'; alert('Connection type: ' + states[networkState]); } </script> </head> <body> <p>A dialog box will report the network state.</p> </body> </html> - ªî£ì¼‹ Gó™-3 Gó™-4 <uses-permission android: name="android.permission. READ_PHONE_STATE"/> Gó™ 4-™ èªù‚û¡ ÜPõîŸè£ù Gó™ ªè£´‚ èŠð†´œ÷¶. Þî¡ ðì‹- 3™ àœ÷¶ èªù‚û¬ù ÜPòô£‹.  𣘈î ꣡Áèœ Ü¬ùˆ¶‹ index.html -™ ܬñˆFì «õ‡´‹.

×