Wednesday, August 29, 2012

Create Client Server Application with Android and ASP.NET

Hi All,

          With this post, I am trying to develop a simple client server application which runs android application in the client side and ASP.NET MVC application in the server side.
          As the first application of this big project, now I am going to tell you how to develop your Android client application.

Requirements for this application.

  • Install Java 
  • Eclipse IDE
  • Installed Android and configured it with your Eclipse
First open your Eclipse IDE and create new Android project.






















Then set project name as "AndroidClient" and click next. In the "select build target wizard", choose a sdk to target and click next. I used Android 2.3.3 here. Give "com.AndroidClient.mobile" as package name and click finished. Please make sure "create activity" option is selected.

 Here we go. Now we have our Android client project. Please add below dew lines of codes to the "onCreate" which resides in src/com.clientServerApp.mobile/AndroidClientActivity.

super.onCreate(savedInstanceState);  
         super.setBooleanProperty("keepRunning", false);  
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
        WindowManager.LayoutParams.FLAG_FULLSCREEN |   
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);  
    super.setIntegerProperty("loadUrlTimeoutValue", 40000);  
    super.loadUrl("file:///android_asset/www/html/login.html");
Now you should create a new "www" folder inside "assets" folder in your project. For that just right click on assets folder and New ->  Folder. Then create another folder named "html" inside www directory and place below html file in the html folder.


 <!DOCTYPE html>  
 <html>  
      <body>   
      <form action="" method="post">   
         <div id="errorstatus"></div>                  
                <br />  
          &nbsp;&nbsp;<label>Username:</label>  
          <input type="text" name="email" id="username"/>  
          <br />  
                &nbsp;&nbsp;<label>Password:</label>  
          <input type="password" name="name" id="password"/>  
          <br />  
          &nbsp;&nbsp;<a href="" onclick="">Forgot Password ?</a>  
          <br /><br />  
            <input type="button" value="Log in" id ="loginButton" name="loginButton" onclick=""/>
         <input type="button" value="Sign Up" id ="signupButton" name="signUpButton" onclick=""/>   
           </form>       
       </body>  
 </html>


Now we are going to run this application using Phonegap. Here we use Phonegap to convert our html file for our Android phone. Please download this the file which include phonegap-1.4.1.jar and other files need for this application from this link.

Now right click on the project and go to BuildPath --> Add External Archieves.. and select location for the phonegap-1.4.1.jar in side downloaded folder. Now you can see it under "Referenced Libraries". Now just copy phonegap-1.4.1.js file which is inside downloaded folder and easily paste to "www" directory by right clicking "www" folder.

Now go to the "res" directory and create a new directory named "xml". Then you should copy both phonegap.xml and plugins.xml from the downloaded folder and paste them in to the created "xml" folder.

As the final thing, you have to do changes in to the Android.manifest file. Please add below code to the Android.manifest file in your project.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.AndroidClient.mobile"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <supports-screens 
    android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:resizeable="true" 
    android:anyDensity="true" />
 <uses-permission android:name="android.permission.CAMERA" />
 <uses-permission android:name="android.permission.VIBRATE" />
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.RECEIVE_SMS" />
 <uses-permission android:name="android.permission.RECORD_AUDIO" />
 <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
 <uses-permission android:name="android.permission.READ_CONTACTS" />
 <uses-permission android:name="android.permission.WRITE_CONTACTS" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
 <uses-permission android:name="android.permission.GET_ACCOUNTS" />
 <uses-permission android:name="android.permission.BROADCAST_STICKY" />
 
    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="com.AndroidClient.mobile.AndroidClientActivity"
            android:label="@string/app_name" 
            android:configChanges="orientation|screenLayout|keyboardHidden" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Here we go..Now you can run our client application by right click on the project, Run As --> Android Application. You can see the output as below.



 Now we want to get texts which will be entered by username and password fields and send them to the server for granting access. We will use java script and Ajax to send client request to the server. We will meet with my next post of how to send client request to the server and its format. We will use Json for send data objects to the server.

Please give you comments about this article. Your valuable comments are really appreciated and they will help me to make much better blog posts than this.

Thank you..!!



Wednesday, April 4, 2012

Sinhala transliterator and Translator for Android

           This is my my first blog in my first blog series. As the first blog, I am going to introduce you a very interesting Android application "Sihala" which gives both transliteration and translation capabilities. That means, user can enter his input text in "Singlish" and then the application will convert it into Sinhala language (transliteration) and display it. In other hand it will display the English meaning of the that sinhala word.

           I developed this application as my 3rd year individual project in my university and now going to improve it with the time.

This is the front view of my application.



Main functionality of the application

           * User can enter his desired Singlish input as text in the first text box.
           * The application will display that word in Sinhala language.
           * Then it will also display the English meaning of that Sinhala word.
           * When user type his word, the application gives suggestions and then user can select one of them.
           * Users can use help guide to get familiar with this "Sihala" application and can see the relevan English characters for each and every sinhala character.



           If  you are going implement an application like this, I will give you my full support for the increment of your application. And If you are really interested in this application, please don't be hesitate to leave a comment below and your suggestions and  comments will be a great strength to me for develop application like this and share my technical knowledge with lot of newcomers for the Android.

           And I will also meet you with future development of this application and very interesting topics which will be very useful to you in your carreer.