Archive for the ‘Mobile Development’ Category

The Criteria of Developing a Mobile App

What is the purpose of developing a mobile app? The first thing you should know about mobile app development is that every app has a purpose. It could be presenting your business idea to the people in the form they want to see or maybe to enhance user experience. So, if you are struggling with finding out the purpose, you would probably have trouble after releasing the app. Image result for mobile app development Features of an app are the next most important thing. They have the power to either make it or break it. But how would you decide what features can make your app the best? Let us go into details:

#1 Research

Image result for research mobile app development A thorough research before starting the development makes your work easier. It helps you to know about the user experience, services you should give, and how to make it better.

#2 Define the purpose

Image result for purpose of mobile app development As I have mentioned, it is the most important thing. If you cannot figure out the purpose of your application, it may not turn out to be the way you want it to be. So, before moving forward, know what exactly do you want from it. Scrutinise its purpose, inspect what are you expecting from it, know what do you want your app to become, and where do you want to see it in next 6 months or a year.

#3 Choosing the mobile app feature

Image result for features of mobile app development When you are done with your research and defined the purpose,  you should move to the next step. Now, you have to choose the mobile app features. Know your product, know the requirements, examine it as a user’s perspective and go ahead with the features.

#4 Determine the success rate

Image result for task check Determining the success rate is not too difficult. The easiest way to determine the success rate is to check whether all the features are working or not. As an example, you wanted a drop down menu in your app, the developer developed it; now if it works they way you want, then the success rate is 90%. Success rate will be 100% only if it goes hand in hand with other features.

#5 Prioritize your features

Image result for priority check The most common strategy to prioritize the features is to classify them according to the requirements. You should also rank priority within each classification. Prioritizing means developing the influential features first.

So, this is our criteria for developing an app. What is yours? Share your views with us in comments!


The technology stack powering the on demand applications

Uber and Ola have given rise to a slew of Ondemand applications which claim themselves to be Uber/Ola of X. Some of the verticals where these applications have found their usability include but not limited to taxi, transportation, Logistics, Home Services, Health apps and so on. In this blog we will go deeper into the various components and technology involved in on Demand Apps. Components Involved in Building and On Demand App In most of the cases there are 3 components involved in building an On-Demand App:
  • A cloud backend for Data Interaction APIs and live dispatch of Jobs
  • An Android/iOS App user to make a job(e.g book a ride with Uber/Ola)
  • An app with the drivers to receive the jobs created by the users and attend to them.
  Lets analyze each of these components in detail and how one can go around building each of them. Web Backend Web Backend is the most critical part of the On Demand applications because backend is what powers both the consumer and the driver apps. The web backend must meet the following requirements for a successful implementation:
  • A Light footprint to dispatch the jobs on fly.
  • A Good dispatch components to maximize the efficiency of the field workers(drivers in case of uber).
  • A Socket connectivity to enable the jobs dispatch and job information to the user.
  • A Good structure for a flexible and structured development
  We have recently worked on Bodhik which is an Ondemand Application for Financial Advisory Services.

Streaming Videos in an Android Application

The blog details on how we can stream videos in an android application. There are basically two parts two parts to the problem:
  1. A streaming server like adobe flash media which can deliver a video stream
  2. Playing the video progressively in your android application with help of a video player
The blog assumes that you already have a file uploaded at some place from where the player can pick up the file to play. The simple and the easiest solution is to use the android VideoView but the problem with the VideoView is it requires the whole file to be downloaded before starts playing. It can be very annoying to serve the videos like this in a real time production application. If however, you are happy with this behavior, you can skip the rest of the blog. Vitamio player Vitamio for android is an android library with a VideoView similar to android’s native VideoView. Vitamio’s VideoView can be used to play or stream the videos. To integrate vitamio,  its library for android needs to be included in the android project. The library is available at the following URL: https://github.com/yixia/VitamioBundle Using Vitamio with an existing Android project After downloading the Vitamio bundle add it into your android project as library. We will now start to build a simple Vitamio VideoView to play the videos Layout In layout xml file add the following lines to add videoView

<io.vov.vitamio.widget.VideoView
 android:id="@+id/video_view"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >

Activity In your activity file import vitamio’s videoView (io.vov.vitamio.widget.VideoView) instead of android native VideoView (android.widget.VideoView). The following sample code demonstrates how you can create a VideoView to stream a video within the Vitamio VideoView.

VideoView mVideoView = (VideoView)findViewById(R.id.video_view);

 //Setting video path(url)
 videoView = mVideoView.setVideoPath(“<Video url>”);

 //Setting main focus on video view
 mVideoView.requestFocus();
 mVideoView.start();

 //Initializing the video player’s media controller.
 MediaController controller = new MediaController(this);

 //Binding media controller with VideoView

 mVideoView.setMediaController(controller);

 //Registering a callback to be invoked when the media file is loaded and ready to go.
 mVideoView.setOnPreparedListener(new OnPreparedListener() {

 @Override
 public void onPrepared(MediaPlayer arg0) {
 //Starting the player after getting information from url.
 mVideoView.start();
 }
 });

Thats it !! You are now ready to stream videos within the vitamio video viewer. There are a lot of options that you can explore within the viewer in the vitamio documentation which is available on their site.

Integrating Google maps API v2 with Android application

Google Maps Android API v2 The Google Maps Android API v2 allows us integrate interactive, feature-rich Google maps to our Android application. Advantage of API v2 over API v1
  • The Maps API now uses vector tiles. Their data representation is smaller, so maps appear in your apps faster, and use less bandwidth.
  • Caching is improved, so users will typically see a map without empty areas.
  • Maps are now 3D. By moving the user’s viewpoint, you can show the map with perspective.
Pre-Requisites for integrating Google Maps API v2 into my Android application
  • The API is distributed as part of the Google Play services SDK, which can be downloaded with the Android SDK Manager. To use the Google Maps Android API v2 in your application, we first need to install the Google Play services SDK.Installing Google Play Services In Eclipse, choose Window > Android SDK Manager. In the list of packages that appears scroll down to Extras folder and expand it. Select the Google Play services checkbox and install the package.
  • Next, to use Google Maps we need to create a valid Google Maps API key. The key is free, we get this key via Google APIS Console. We have to provide our application signature key and the application package name in order to get the Google Maps API key
What is Application signature key? The Maps API key is based on a short form of your application’s digital certificate, known as its SHA-1 fingerprint. The fingerprint is a unique text string generated from the commonly-used SHA-1 hashing algorithm. Because the fingerprint is itself unique, Google Maps uses it as a way to identify our application. Generating SHA1 Key Find .android directory on your device : This directory is under your home directory. Windows Vista/7: windows installation drive: (C,DE, whatever)\Users\\.android OS X and Linux: ~/.android Find debug Keystore File called debug.keystore lies in .android directory To create the SHA-1 for your debug keystore you use the keytool command from your JDK installation pointing to the debug.keystore file. Command:
keytool -list -v -alias androiddebugkey \-keystore &lt;path_to_debug_keystore&gt;debug.keystore \-storepass android -keypass android
Now follow following documentation to generate API key https://developers.google.com/maps/documentation/android/start#obtaining_an_api_key
  • Now you have installed Google play services library and generated an API key for you app lest now move to actual process to integrate a google map
Steps to Integrate Google maps to an Android application
  • Create a new android project in Eclipse, with package name that you have registered with Google console to get API key
  • Import Google play Services library to your workspace Browse to /extras/google/google_play_services/libproject/google-play-services_lib and select google-play-services_lib
  • Add this Project to your android app as -> Properties -> Android -> Library, Add -> google-play-services_lib into your project
  • Code in MainActivity should look like this
  • public class MainActivity extends Activity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     }
  • Maps are now encapsulated in the MapFragment class, an extension of Android’s Fragment class.Now you can add a map as a piece of a larger Activity.With a MapFragment object, you can show a map by itself on smaller screens, such as mobile phones, or as a part of a more complex UI on larger-screen devices, such as tablets.
What is MapFragment? It is a Map component in an app. This fragment is the simplest way to place a map in an application. It’s a wrapper around a view of a map to automatically handle the necessary life cycle needs. Being a fragment, this component can be added to an activity’s layout file simply with the XML below.

<?xml version="1.0" encoding="utf-8"?>
 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/map"
 android:layout_width="match_parent"
 android:layout_height="match_parent" android:name="com.google.android.gms.maps.MapFragment"/>

so we need to replace content ofres/layout/activity_main.xml with code above
  • Add the following tag into your AndroidManifest.xml just before the closing tag From here, the Maps API reads the key value and passes it to the Google Maps server, which then confirms that you have access to Google Maps data.
    <meta-data android:name="com.google.android.maps.v2.API_KEY"android:value="<strong>your_api_key</strong>"/>
  • Your application now also needs the following permissions in the AndroidManifest.xml
    <permission android:name="your_package_name.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
     <uses-permission android:name="your_package_name.permission.MAPS_RECEIVE"/>
     <uses-permission android:name="android.permission.INTERNET"/>
  • Maps v2 uses OpenGl so the following uses-feature is also required <uses-feature android:glEsVersion=”0x00020000″ android:required=”true”/>
  • Thats it !! Build and run your application.
  • You should see a map. If you don’t see a map, please confirm if you have missed out any of the configurations.

Debugging Android APK on Device using Eclipse

Lets accept it, a lot of us face this problem where debugging doesn’t help on emulator and one has to debug the android application on the device itself. I will try to explain on how to do this in a step by step manner. Before actually going into the topic let us understand what ADB is. ADB The Android Debug Bridge (ADB) is a command line tool that handles debug communication between a debugger on the host (DDMS) and an Android image running on the target (Emulator or Device). Setting up a Device FOR DEBUGGING Debugging APK from device using Eclipse
  • Export signed/unsigned apk from Eclipse and install on device
  • Connect device to your machine using USB cable
  • Now click on windows >open perspective >DDMS in top menu eclipse
  • Select Devices
  • Following screen will apper
image
  • when you click on your device, all the running apps will be shown
  • Now click on green debug icon on top as shown in pic below
image Your application is now being debugged on device. Hope this saves some of our valuable time !!

Database Operations with ORM Lite

In the first blog post, we discovered about ORMLite as a formidable ORM for use in android applications. Here we will delve deeper into how to perform various database operations using ORMLite Query Operation in ORM Lite The DAOs provide basic methods to query for an object that matches an id (queryForId) and query for all objects (queryForAll), iterating through all of the objects in a table . However, for more custom queries, there is the queryBuilder() method which returns a QueryBuilder object for the DAO with which you can construct custom queries to return a sub-set of your tables. Query Builder is something that assists in building SQL query (SELECT) statements for a particular table in a particular database. 1.Query for all Returns the list of all records in the table we have in build function queryForAll();
// get our dao
 RuntimeExceptionDao<DemoORMLite, Integer> DemoORMLiteDao = getHelper().getDemoORMLiteDao ();

// query for all of the data objects in the database
 List<SimpleData> list = simpleDao.queryForAll();
2. Query for id Returns the record corresponding to given id we have in build function queryForId(id);
TEntity entity = <strong>this</strong>.dao.queryForId(id);
3. Query for particular field name Here we use QueryBuilder to query for field “lastname” and return the list of records that have last_name =”lastname”
Public List<DemoORMLite> RetrieveByLastName(String lastname)throws SQLException {
QueryBuilder<TEntity,Integer> queryBuilder = dao.queryBuilder();
List list;
queryBuilder.where().eq("last_name", lastname);
list = queryBuilder.query();
return list;
}
Deleting a record in ormlite DeleteBuilder assists in building sql DELETE statements for a particular table in a database. Sample Code that deletes elements from table by argument
DatabaseHelper helper = OpenHelperManager.getHelper(App.getContext(), DatabaseHelper.class);</pre>
//get helper
 Dao dao = helper.getDao(YOUR_CLASS.class);

//get your Dao
 DeleteBuilder<CanteenLog, Integer> deleteBuilder = dao.deleteBuilder();
 // CanteenLog here is table name

deleteBuilder.where().eq("FIELD_NAME", arg);

deleteBuilder.delete();

Order by in ormlite Syntax: orderBy(String columnName, boolean ascending) Add “ORDER BY” clause to the SQL query statement to order the results by the specified column name. Use the ascending boolean to get a ascending or descending order. This can be called multiple times to group by multiple columns.
QueryBuilder<Visit, Integer> qb = getHelper().getyourdaoname().queryBuilder();
 qb.where().eq("Field_name", fieldname);
 qb.orderBy("order_according_to_this_field", false);

Using Max in Ormlite

long max = fooDao.queryRawValue(

"select max(modified) from foo where userid = ?", id);
 // now perform a second query to get the max row
 Foo foo = fooDao.queryBuilder().where().eq("modified", max).queryForFirst();

Set default value to column in ORMLite
@DatabaseField(defaultValue = "unknownName", canBeNull = true)
Here we explored various simple ORMLite operations. If you have used ORMLite in more advanced way, Please feel free to drop a comment below !!

ORMLITE – Light Weight Object Relational Mapping – An Introduction

OVERVIEW ORM Lite provides a lightweight Object Relation Mapping between Java classes and SQL databases. ORM Lite supports JDBC connections to MySQL, Postgres, H2, SQLite, Derby, HSQLDB, and Microsoft SQL Server. ORM Lite also supports native database calls on Android OS. Using ORM Lite with Android Downloading ORMLITE To get started with ORM Lite, We need to download the ORM Lite jar files. These can be downloaded from ORM Lite release page Once we have downloaded ORM Lite, we will need to add it as an external library to our android project. Just Drop the jar file into your project’s libs/ subdirectory. We only need the ormlite-android-4.14.jar, not the ORM lite-core or any other packages. Getting Started with ORM Lite To get started with ORM lite we need to create our own database helper class which should extend the OrmLiteSqliteOpenHelper class. This class creates and upgrades the database when the application is installed and also provide the DAO(Data Access Object) classes used by other classes. The helper class must implement the methods

onCreate(SQLiteDatabase sqliteDatabase, ConnectionSource connectionSource)

onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion)

onCreate creates the database when app is first installed while onUpgrade handles the upgrading of the database tables when we upgrade our app to a new version. The helper should be kept open across all activities in the app with the same SQLite database connection reused by all threads. If we open multiple connections to the same database, stale data and unexpected results may occur. It is recommended to use the OpenHelperManager to monitor the usage of the helper – it will create it on the first access, track each time a part of our code is using it, and then it will close the last time the helper is released. Once we define our database helper and are managing it correctly, We will use it in our Activity classes. An easy way to use the OpenHelperManager is to extend OrmLiteBaseActivity for each of your activity classes – there is also OrmLiteBaseListActivity, OrmLiteBaseService, and OrmLiteBaseTabActivity. These classes provide a helper protected field and a getHelper() method to access the database helper whenever it is needed and will automatically create the helper in the onCreate() method and release it in the onDestroy() method. Here is sample DatabaseHelper class http://ormlite.com/android/examples/DatabaseHelper.java Creating Table using ORM Lite There are a few things to notice when we use ORM Lite:
  1. We just annotate our class as a table and its members as fields and we’ re almost done with creating a table
  2. ORM Lite handles all of the basic data types without any explicit work on your part (integers, strings, floats, dates, and more).
  3. It is mandatory to have a no argument constructor in our class
In onCreate method of Databasehelper we create tables with help of TableUtils like
TableUtils.createTable(connectionSource, SimpleData.class);,
SimpleData here is name of table An example code to create Table in the onCreate callback:
 /**
 * This is called when the database is first created. Usually you should call createTable statements here to create
 * the tables that will store your data.
 */
 @Override
 public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
 try {
 TableUtils.createTable(connectionSource, SimpleData.class);
 } catch (SQLException e) {
 Log.e(DatabaseHelper.class.getName(), "Can't create table", e);
 throw new RuntimeException(e);
 }

Here is sample ORMLite table class

/**
 * A simple demonstration object we are creating and persisting to the database.
 */
 public class SimpleData {

// id is generated by the database and set on the object automagically
 @DatabaseField(generatedId = true)
 int id;
 @DatabaseField(index = true)
 String string;
 @DatabaseField
 long millis;
 @DatabaseField
 Date date;
 @DatabaseField
 boolean even;

SimpleData() {
 // needed by ormlite
 }

public SimpleData(long millis) {
 this.date = new Date(millis);
 this.string = (millis % 1000) + "ms";
 this.millis = millis;
 this.even = ((millis % 2) == 0);
 }

@Override
 public String toString() {
 StringBuilder sb = new StringBuilder();
 sb.append("id=").append(id);
 sb.append(", ").append("string=").append(string);
 sb.append(", ").append("millis=").append(millis);
 SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.S");
 sb.append(", ").append("date=").append(dateFormatter.format(date));
 sb.append(", ").append("even=").append(even);
 return sb.toString();
 }
 }

Hope that the blog gets you running on ORMLite, In the subsequent posts, we will explore more about ORMLite and how to use it to manipulate/retrieve data objects. References:
  1. ORMLite Sample table class (http://ormlite.com/android/examples/SimpleData.java)
  2. ORMLite example: (http://ormlite.com/android/examples/)

Bundle and plist in Objective C – An Overview

Bundle: A bundle is a structure used for packaging software on Mac OS X. The main bundle is simply the bundle of the application that is running. So, for instance, the main bundle of the Apple mail program is /Applications/Mail.app. Types of Bundle: There are three general types of bundles: Application bundles Application bundles contain an executable and all its related resources, such as nib files, image files, and localized strings. Plug-in bundles Plug-in bundles provide code that extends or enhances the functionality of a host application in some way. Framework bundles Framework bundles contain dynamic shared libraries, as well as header files, images, and documentation. How to access bundle resource: When a user launches an application, it finds the code and resources in the main bundle that it immediately needs and loads them into memory. Thereafter, the application can dynamically (and lazily) load code and resources from the main bundle or subordinate bundles as required. plist: This file is an XML-based text file that contains specific types of key-value pairs. These key-value pairs specify information about the bundle, such as its ID string, version number, development region, type, and other important properties. Importance: A great way to store dictionary data that does not change during runtime is in a .plist file. Example:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Info.plist"];
NSDictionary *plistData = [NSDictionary dictionaryWithContentsOfFile:finalPath];
Notes
  • The settings bundle is for having settings that show up in the system Settings.app.
  • You can use a plist to store settings that you change within the app itself.
Enjoy your day !!

Integrating Google oAuth APIs with iPhone Applications

This blog is an effort to round up on how to consume Google’s REST APIs in an iPhone App.  As usual with RESTful APIs, the client specifies an action using an HTTP verb such as POST, GET, PUT, or DELETE and the resource by a globally-unique URI of the following form: https://www.googleapis.com/apiName/apiVersion/resourcePath?parameters The response will be returned by the API in JSON format. The APIs use OAuth 2.0 protocol for authentication and authorization. Google supports several OAuth 2.0 flows that cover common web server, JavaScript, device, installed application, and server to server scenarios. Here we are dealing with installed application on device scenario. Steps to integrate the Google APIs in a normal iOS application are not different than the normal OAuth flow. Register Application: First of all , the application must be registered through Google API console. The result of this registration process is a set of values that are known to both Google and application (e.g. client_id, client_secret, redirect_uri, etc.). The set of values generated varies based on the type of application you are building. Another thing that you need to do is to turn on the APIs that your application needs to access in API Console. Obtain an Access Token from the Google Authorization Server: This is the normal OAuth flow where we need to get the access token to call an API. For authorization call this url, it will show a gmail login window which needs user login credentials:
Parameters Value
response_type code
client_id the client_id obtained from the APIs Console.
redirect_uri the redirect_uri values registered at the APIs Console.
scope space delimited set of permissions the application requests.
state anything
In iPhone, application can fetch authorization code from following code:
NSString *tokenCode
   = [theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('title')[0].innerHTML;"];
Authorization code will be something like “token = tokenValue”. Retrieve the tokenValue and use that to obtain an access token from Google by shooting the post request to following url.
<pre><em id="__mceDel">NSString *url = @"https://accounts.google.com/o/oauth2/token?";
NSString  *data =[NSString stringWithFormat: @"code=%@&client_id=testing.apps.googleusercontent.com&client_secret=OxVwVVgYqvlgjoidgdfghdDv&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code",token];
Response of above url will return the dictionary having token, expire time, refresh token and token type. { “access_token”:”1/fFAGRNJru1FTz70BzhT3Zg”, “expires_in”:<expiry_time>, “token_type”:”Bearer”, “refresh_token”:”1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI” } After obtaining access token above, you are ready to call the Google API for your purpose. Calling Google Api: After application has obtained an access token, application can access a Google API by including it in either an access_token query parameter or an Authorization: Bearer HTTP header. Application can call on those api which are passed as scope in authorization URL. For example, a call to theCalendar API using the access_token query string parameter looks like this: https://www.googleapis.com/calendar/v3/users/me/calendarList?access_token=1/fFAGRNJru1FTz70BzhT3Zg This will return entries on the user’s calendar list. Similarly you can call any other API from the API console which requires an OAuth Token. Enjoy building the cool apps that integrate with Google API !!

iOS 6 Smart App Banners

With the release of iOS 6, Apple introduced a new way of promoting your apps. The feature is called Smart App Banners and it can be seen in Safari browser of your iOS 6 device.
  • As you can see, the app banner will be visible at the top of the webpage by pushing the whole page down a little, so this improves the browsing experience as compared to other promotional methods where adds are shown as full page display or as a pop-up window.
  • Tapping the banner will move you to the app itself or app in the app-store depending upon whether you have that app installed on your device or not.
  • Implementing the Smart app banner is very easy, just you need to add a meta tag of the following type in the head section of the page on which you want to show this banner :-
  • 
    <meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
    
  • content attribute of this meta tag have 3 parameters (1 compulsory + 2 optional) which are:-
  • app-id (required) :- The itunes id of your app.
  • affiliate-data (optional) :- The itunes string of the affiliate. Affiliates are the persons who earn some part of money as commission, if that app is bought by some client.
  • app-argument (optional) :- The url on which the app will open & jump if it is already installed on your device. Basically it provides a contextual navigation to your app.
  • Here are some quick examples of the meta tag :-
  • <meta name="apple-itunes-app" content="app-id=13456789">
    <meta name="apple-itunes-app" content="app-id=123456789, affiliate-data=partnerId=123&siteId=123456">
    <meta name="apple-itunes-app" content="app-id=123456789, app-argument=http://abcd/1159">
    
Enjoy the seamless promotional banners for your application !!