Saturday, 30 April 2016

Getting started with Phonegap

Why Phonegap?
               Phonegap is a great framework to build cross platform apps(Android, iOS, Windows etc.,) using HTML, CSS, jQuery and it is very simple and easy.

What is Phonegap Desktop App?
              The Phonegap desktop application provides drag and drop for creating Phonegap applicaitons. It's an alternative for Phonegap CLI.
         The best advantage of Phonegap desktop app is to preview your phonegap app directly in your mobile instead of emulator by installing Phonegap Developer App in your mobile.


What is Phonegap CLI(Command Line Interface)?
              The Phonegap CLI provides command line interface for creating Phonegap apps. It's an alternative for Phonegap Desktop App. CLI is having some additional features over Phonegap desktop those are building, running and packaging your Phonegap app. If you are comfortable with CLI, it's better to use Phonegap CLI.

Note: Both ways you can develop phonegap apps. But my suggestion is to install both ways  bcoz one is for previewing in your mobile and another one is for building,running and packaging.

You can see the post here How to install Phonegap Desktop App in Windows plastform?



Please let me know help from Phonegap side.


Sunday, 17 April 2016

How to work with SQLite in Phonegap?

What is SQLite?
      Serverless, zero-configuration, very small, light weight, self-contained(no external dependency). It is written in ANSI-C. Available on UNIX(Linux, Mac OS-X, Android, iOS) and Windows.

SQLite in Phonegap:
      First, need to install SQLite plugin in phonegap working project(Assuming you already created phonegap project). Go to that phonegap working project in cmd(windows) and type below command to install SQLite plugin.

>> phonegap plugin add cordova-sqlite-storage

Now we are going to implement CRUD operations with SQLite using jQuery:

Sample Syntax for all operations:

     var db = window.openDatabase({name:"TestDb.db"});   - To create database and connection

     db.transaction(function(transaction){                               - For database transactions
          var query = "SQL query";
          transaction.executeSql(query, [parameters],                - For query execution
          function(tx, result){
                 //success
          },
         function(error){
        });                                                               
     });

Table creation in database:

     db.transaction(function(transaction){                           
          var query = "CREATE TABLE IF NOT EXISTS phonegapsolutions (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, usermail TEXT)";
          transaction.executeSql(query, [],                               
          function(tx, result){
                 alert("Table created successfully");
          },
         function(error){
                 alert("Error in table creation");
        });                                                               
     });

Insertion:

     var username = "edukondalu";
     var usermail = "edukondaluthaviti@gmail.com";
    db.transaction(function(transaction){                           
          var query = "INSERT into phonegapsolutions (username, usermail) VALUES (?, ?)";
          transaction.executeSql(query, [username, usermail],                               
          function(tx, result){
                 alert("Inserted");
          },
         function(error){
                 alert("Error in insertion");
        });                                                               
     });

Get all inserted data:

    db.transaction(function(transaction){                           
          var query = "SELECT * from phonegapsolutoins";
          transaction.executeSql(query, [],                               
          function(tx, result){
                 for(var i=0;i<result.rows.length;i++){
                     var item = result.rows.item(i);
                     var html = "<li>" + item["username"] + " " + item["usermail"]  + "</li>";
                }
               $("#id").html(html);
          },
         function(error){
                 alert("Error in Getting all data");
        });                                                               
     });

Updation:

     var id = $("#id").text();
     var username = $("#username").val();
     var usermail = $("#usermail").val();
    db.transaction(function(transaction){                           
          var query = "UPDATE phonegapsolutions SET username = ?, usermail = ?where id = ?";
          transaction.executeSql(query, [username, usermail, id],                               
          function(tx, result){
                 alert("Updated");
          },
         function(error){
                 alert("Error in updation");
        });                                                               
     });

Deletion:

    db.transaction(function(transaction){                           
          var query = "DELETE from phonegapsolutions where id = ?";
          transaction.executeSql(query, [id],                               
          function(tx, result){
                 alert("Deleted");
          },
         function(error){
                 alert("Error in deletion");
        });                                                               
     });

DROP:

    db.transaction(function(transaction){                           
          var query = "DELETE TABLE IF EXISTS phonegapsolutions";
          transaction.executeSql(query, [],                               
          function(tx, result){
                 alert("Table Deleted");
          },
         function(error){
                 alert("Error in table deletion");
        });                                                               
     });

Please let me know any help from phonegap side.

Saturday, 9 April 2016

Native vs. Hybrid apps development

We can develop android apps in two ways:

1. Native apps development
2. Hybrid apps development

1. Native apps development
       Native android apps, the name itself tells it has been developed for use on a particular platform.
Languages: Java
Environment: Android Studio(Recommended), eclipse, netbeans etc.,


2. Hybrid apps development
       Hybrid android apps are web applications(or web pages) in the native browser such as UIWebView in iOS, and WebView in Android.
Languages: HTML, jQuery, CSS
Environment: Phonegap(Apache Cordova), IBM Worklight etc.,


DescriptionNative apps developmentHybrid apps development
Development LanguageNative OnlyNative and Web / Web Only
Device AccessCompleteComplete
Device Specific FeaturesHighModerate
SpeedVery FastMedium
App StoreAvailableAvailable
Approval ProcessMandatoryLow Overhead
Code PortabilityNoneHigh
Advanced GraphicsHighModerate
UIHighModerate
Access to Native APIsHighModerate
Development CostExpensiveReasonable