Friday, 10 July 2015


Android Syllabus

  1. Introduction to Android?

  1. Android History Overview

  1. Android Version Evolution

  1. Android Architecture brief

  1. IDE and Setup Environment

  1. Android App Development
Design and views
Enable action for views
Android manifest

  1. Project Structure
Source
Resource
Manifest

  1. Building Blocks
Activity
Service
Broadcast Receiver
Content Provider

  1. Intent
Implicit Intent
Explicit Intent
Bundle data passing
Intent Filters

  1. XML for Design
Design Overview
XML Overview
Views
Layouts

  1. Manifest File
manifest
application
activity
uses-sdk
permission

  1. Emulator
Steps to create
Launching
Editing Emulator

  1. DDMS
Device
Emulator Control
File Explorer
System Information
Network Statistics
Allocation Tracker

  1. SharedPreferences(Permanent Storage)
Save Data
Retrieve Data
Update Data
Clear Data

  1. Notifying User
Toast
Alert Dialog
Notification

  1. Database using Android Methods
Creating database
Add values
Retrieve values
Listview updation

  1. Web service Handling
Why web services?
Handling with Android Methods
JSON Parsing

  1. APK file generation
Process behind APK Generation
Steps to Create
Keystore file

  1. Google play submission
Account Creation
Store Listing
Uploading APK

  1. Developer Tips
Naming Conventions
Coding standards
Best practice
Developer Advice
Tutorial sites

Monday, 22 December 2014

App upload on Google Play

Uploading APK sounds simple task but  need more work and attention.


                                      Before Uploading Android app to Google Play

   Points to keep in mind before uploading the .apk file to Google Play are,

  • Core of App
 Must be sure, the complete app/core of the app is developed and tested well. Check whether the app is satisfies the requirements.
  • Code Review
Once the app is developed as per the requirement then it is the time for Code Review. Because code review will give the chance for reduce coding, performance optimization and memory optimization etc. Tools are available for this PMD and Find Bug.
Note: If you are using Android Studio then inbuilt tool is available for code review.  Click on Analyze -> Inspect Code.
  • Android Manifest.xml
This is the file can explain about the app to Google play. Because Google Play determines and create filters for avoiding failed installation. Ex: Choosing Minimum SDK version and Maximum SDK version will restrict the app visible only between these versions(In Android Studio build.gradle have the provision for SDK version).

  • Testing 
To deliver the quality product we must test the app before delivery. Android SDK come with best tools and one great tool is Monkey Runner for stress test the app and more.

  • Store Listing
Store Listing is simply a list of required fields for uploading .apk. Fields like images files and text content which will explains about the app to the users.
  • Check List
Follow the Google Checklist and your own checklist. Creating your own checklist is from your experience. Ex: Own checklist is some times after uploading you may forgot to do in the uploaded apk. So note down the points you missed every time.

Friday, 17 August 2012

Log in Android

                       Trace Android Issues

Log:

The Android logging system provides a mechanism for collecting and viewing system debug output. Logcat dumps a log of system messages, which include things such as stack traces when the emulator throws an error and messages that you have written from your application by using the Log class. You can run LogCat through ADB or from DDMS, which allows you to read the messages in real time.


This is like System.out in java or printf in C language.

Where ever you want to trace the values you can use this.

Types of logs:

* Verbose - v(String , String)
* Debug    - d(String , String)
* Info        - i(String , String)
* Warning - w(String , String)
* Error      - e(String , String)

We can also able to filter them.

Example:


int A = 10;
Log.d(this.toString,"Current Value of A "+ A);

The above code will produce 10 as answer.


Fundamentals of Android

                                Fundamentals of Android

These are the basic building blocks for android  

 * Activity
* Service
* Broadcast Receiver
* Content Provider.


An activity represents a single screen with a user interface.
The user can interact with the activity i.e. click the button.

A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface.

Example:
       Listening Music is the service. Because no user interaction is neccessary to play music. Once you start it will playing all the songs.
 
A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. 

Example:
       Consider that you are going to develop message sending application. For choosing the contacts you need to add contacts one by one in your application. 
       Instead of that you just share the contact which is in your phone contacts.

A broadcast receiver is a component that responds to system-wide broadcast announcements.

            Example:
                      It reacts some thing, when the phone receive any messages or phone etc.



Thursday, 24 May 2012

              MD5 Encryption in Android

Lets start the tutorial for md5 encryption in android.

MD5 is the best practice to handle the secured data like password etc.
In android we can able to achieve this using few simple code.

Create new android project and copy and paste the below java code.

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class DataEncryptionActivity extends Activity {
    String strNormalValue, strEncrytedValue;
    EditText edtValue;
    Button btnEncrypt;
    TextView tvEncrypt;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        edtValue = (EditText) this.findViewById(R.id.edt_to_encrypt);
        tvEncrypt = (TextView) this.findViewById(R.id.txt_encrypt);
        btnEncrypt = (Button) this.findViewById(R.id.btn_encrypt);
        btnEncrypt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                strNormalValue = edtValue.getText().toString().trim();
                strEncrytedValue = getMD5(strNormalValue);
                tvEncrypt.setText(strEncrytedValue);
            }
        });

    }

    public String getMD5(String src) {
        try {
            // Create MD5 Hash
            MessageDigest digest = java.security.MessageDigest
                    .getInstance("MD5");
            digest.update(src.getBytes());
            byte messageDigest[] = digest.digest();

            // Create Hex String
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                String h = Integer.toHexString(0xFF & messageDigest[i]);
                while (h.length() < 2)
                    h = "0" + h;
                hexString.append(h);
            }
            return hexString.toString();

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}


Copy and paste it in main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/edt_to_encrypt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btn_encrypt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Convert to MD5" />

    <TextView
        android:id="@+id/txt_encrypt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:singleLine="false" />

</LinearLayout>




 Full Source code for MD5 Encryption.

Friday, 11 May 2012

                Android Login Email & Password Validation

Here i going to validate the email and password.
The complete source code for the LoginValidationProject

follow my steps, Create the project with following attributes.

Project name         : LoginValidationExample
Build Target           : Android 2.1
Application name   : LoginValidationExample
Package name        : com.android.dhamu.validation
Create Activity      : LoginScreen

Step 1:

 Rename the main.xml file as login_screen.xml. Copy and paste the below xml coding in it.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Login Screen"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#00ff00" />

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dip"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_margin="30dip"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/edt_username"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dip"
                android:layout_marginTop="20dip"
                android:hint="Username"
                android:inputType="textEmailAddress"
                android:paddingLeft="10dip"
                android:paddingRight="10dip"
                android:singleLine="true"
                android:typeface="normal" >

                <requestFocus>
                </requestFocus>
            </EditText>

            <EditText
                android:id="@+id/edt_password"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dip"
                android:layout_marginTop="10dip"
                android:hint="Password"
                android:inputType="textPassword"
                android:paddingLeft="10dip"
                android:paddingRight="10dip"
                android:password="true"
                android:singleLine="true"
                android:typeface="normal" >
            </EditText>

            <Button
                android:id="@+id/btn_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Login" >
            </Button>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>


Now you got the screen like



Step 2:

Create the home_screen.xml in res/layout folder, Then copy and paste the below xml coding in it.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Home Screen"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#00ff00" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Login completed successfully"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#ff00ff" />
    </LinearLayout>

</LinearLayout>

Now you got the screen like


Step 3:

Copy the below java coding and paste it in LoginScreen.java file.

package com.android.dhamu.validation;

import java.util.regex.Pattern;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginScreen extends Activity {
    EditText edtUsername,edtPassword;
    Button btnLogin;
    String strUsername,strPassword;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_screen);
       
        edtUsername = (EditText)this.findViewById(R.id.edt_username);
        edtPassword = (EditText)this.findViewById(R.id.edt_password);
        btnLogin = (Button)this.findViewById(R.id.btn_login);
       
        btnLogin.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                strUsername = edtUsername.getText().toString().trim();
                strPassword = edtPassword.getText().toString().trim();
               
               
                if (isInternetConnected()) {

                    if (isUserNameNotEmpty()) {

                        if (isValidEmail()) {

                            if (isPassWordNotEmpty()) {
                               
                                LoginScreen.this.startActivity(new Intent(
                                        LoginScreen.this,
                                        HomeScreen.class));
                            }
                        }

                    }

                }
               
               
            }
        });
       
    }
   
   
    public boolean isInternetConnected() {

        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
                .getState() == NetworkInfo.State.CONNECTED
                || connectivityManager.getNetworkInfo(
                        ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
            return true;
        } else
            Toast.makeText(this, "Please check your internet connection",
                    Toast.LENGTH_SHORT).show();
        return false;
    }

   
    // Checking the Email whether it is valid or not.

    private boolean isValidEmail() {
        final Pattern EMAIL_ADDRESS_PATTERN = Pattern
                .compile("[a-zA-Z0-9+._%-+]{1,256}" + "@"
                        + "[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" + "(" + "."
                        + "[a-zA-Z0-9][a-zA-Z0-9-]{0,25}" + ")+");

       

        if (EMAIL_ADDRESS_PATTERN.matcher(strUsername).matches()
                && !strUsername.equalsIgnoreCase("")) {

            return true;
        } else {
            Toast.makeText(this, "Please enter valid Email ID", Toast.LENGTH_SHORT)
                    .show();
            return false;
        }

    }
   

    // Checking whether the username is not empty

    public boolean isUserNameNotEmpty() {
        if (strUsername.equalsIgnoreCase("")) {
            Toast.makeText(this, "Please enter the Email ID", Toast.LENGTH_SHORT)
                    .show();
            return false;
        } else {
            return true;
        }

    }

   
    // Checking whether the password is not empty

    public boolean isPassWordNotEmpty() {
        if (strPassword.equalsIgnoreCase("")) {
            Toast.makeText(this, "Please enter the Password", Toast.LENGTH_SHORT)
                    .show();
            return false;
        } else {
            return true;
        }

    }

}

Step 4:

Create the HomeScreen.java in src folder and paste the below java code in it.

package com.android.dhamu.validation;

import android.app.Activity;
import android.os.Bundle;

public class HomeScreen extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_screen);
    }
}

Step 5:

AndroidManifest.xml file

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

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="7" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="LoginScreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>
In AndroidManifest.xml file,

1) Add the permission for INTERNET and ACCESS_NETWORK_STATE.
2) Add the HomeScreen.java in application.

Here is the complete SourceCode for LoginValidation.