Pages

Monday, 12 March 2012

SQLite

Introduction:-
                      SQLite is a popular choice for local/client storage on web browsers. It has many bindings to programming languages.SQLite is an Open Source Database which is embedded into Android. SQLite supports standard relational database features like SQL syntax, transactions and prepared statements. In addition it requires only little memory at runtime (approx. 250 KByte).

In Android:-
                    
SQLite is available on every Android device. Using an SQLite database in Android does not require any database setup or administration.
You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform.

Android Architecture :-
 1.SQLiteOpenHelper:-
                                      SqLiteOpenHelper are use to database creation and managing database version.
In SQLiteOpenHelper you implement onCreate(SQLiteDatabase), onUpgrade(SQLiteDatabase, int, int) and and optionally onOpen(SQLiteDatabase) method.

-onCreate(SQLiteDatabase db):-
                                            Called when the database is created for the first time.
                                 @Override
                                  public void onCreate(SQLiteDatabase db)
                                 {
                                             db.execSQL(DATABASE_CREATE);
                                  }

- onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion):-
                                             Called when the database needs to be upgraded.
                                    @Override
                                     public void onUpgrade(SQLiteDatabase db, int oldVersion,  int newVersion)
                                     {
                                             Log.w(TAG, "Upgrading database from version " + oldVersion
                                              + " to "
                                              + newVersion + ", which will destroy all old data");
                                               db.execSQL("DROP TABLE IF EXISTS titles");
                                              onCreate(db);
                                     }

- onOpen(SQLiteDatabase db):-
                                            Called when the database has been opened.
                                    
 2.SQLiteDatabase:-
                                      SQLiteDatabase is the base class for working with a SQLite database in Android. SQLiteDatabase has methods to create, delete, execute SQL commands, and perform other common database management tasks.

         3.Package:-
                           android.database.sqlite contain all related package of SQLite.

Creating Database:-
                                Following code show how to create database.Suppose it's a employee data including name and salary.                             
     private static final int DATABASE_VERSION = 1;
     private static final String DATABASE_CREATE =
                   "create table salary (_id integer primary key autoincrement, "
                   + "name text Not Null, salary text Not Null);";

Inserting Data in Database:-
                                           Using following function you can insert data into database.

                                public long insertsalary(String name, String salary)
                                {
                                               ContentValues initialValues = new ContentValues();
                                                initialValues.put(KEY_NAME, name);
                                                initialValues.put(KEY_SALARY, salary);
                                                return db.insert(DATABASE_TABLE, null, initialValues);
                                 }

Retrieving Data:- 
                     1. One Record:- Fetch one record at a time.
                                         public Cursor getdetails(String id) throws SQLException
                                        {
                                                        Cursor mCursor =
                                                                    db.query(true, DATABASE_TABLE, new String[]
                                                                     {
                                                                             KEY_ROWID,
                                                                              KEY_NAME,
                                                                             KEY_SALARY,
                                                                       },
                                                                     KEY_ROWID + "=" + id, null, null, null, null, null);
                                                       if (mCursor != null)
                                                      {
                                                                    mCursor.moveToFirst();
                                                       }
                                                      return mCursor;
                                       }

                 2. AllRecord:- Fetch all record..
                                   public Cursor getAllDetails()
                                  {
                                        return db.query(DATABASE_TABLE, new String[]
                                         {
                                                  KEY_ROWID,
                                                  KEY_NAME,
                                                  KEY_SALARY,
                                         },
                                             null,null,null,null,null);
                                   }
How to find Database:-
                                   SQLite database is located at DDMS. 
Select DDMS- Select FileBrowser\Data\Data\Your Package Name\Database\"database_Name.db".

SQLiteBrowser:-
                                 You find Database file but how to check the content of database whether insert correctly or not?. SQLite Browser is use to check the database content. You need to download it from following link.
Download SQlite Browser from here  

Delete One Record:-
                                 It's very easy to delete single record from database. You need only call the Delete() from your Activity and pass appropriate value(integer or string). You need to apply different query for integer and String.

                                1.Integer Parameter.
                                  public void delete(int value)
                                 {
                                        try{           
                                                   SQLiteDatabase db= this.getWritableDatabase();
                                                   db.delete(TABLE_NAME, COLUMN_ID+"="+value, null);

                                             }
                                             catch(Exception e){
                                             e.printStackTrace();
                                             }
                                  }    

        
                               2.String Parameter.
                                public void deleteBName(String keyword)
                               {
                                    try
                                    {
                                        SQLiteDatabase db=this.getWritableDatabase();
                          db.delete(TABLE_NAME,COLUMN1+"=?", new String [] {String.valueOf(keyword)});
                                    }
                                   catch(Exception e)
                                   {
                                           e.printStackTrace();
                                   }          
                             }

                   
Delete all Record:-
                               Following function delete all record.
                                public void deleteAll(){
                                try{           
                                       SQLiteDatabase db= this.getWritableDatabase();
                                       db.delete(TABLE_NAME, null, null);
                                     }catch(Exception e){
                                    e.printStackTrace();
                                     }
                               }


Thank you!

Save Tree Save Life.....

                                                              

Sunday, 11 March 2012

Telnet with Emulater.

Introduction:-
                     Telnet is a network protocol used on the Internet or LAN to provide a bidirectional interactive text-oriented communications facility using a virtual terminal connection. By default telnet is not enable in window, we need to enable it.

Enable Setting:-
                           Click on Start - Control Panel - Program - Then click on "turn windows feature ON/OFF"
-Enable Telnet.   Now it's available for use.

With Emulator:-
                       Open command prompt- "Path to your sdks"\ telnet localhost 5554 then press Enter.
                       5554:- Number of emulator which you want to connect with telnet.
                       Path:- C:\users\san\android-sdks\platform-tools (Generally, it may different in your case).

Example:- C:\users\san\android-sdks\platform-tools\telent loaclhost 5554
       After clicking enter following screen will open.(should emulator open before enter this syntax).

Help provide you other command.

Passing value from Telnet to Emulator:-
                                                       "geo" command are use to send Longitude and latitude to emulator.

Syntax:- geo fix longitude latitude
Example:- geo fix 76.57492 18.457

this value check with emulator value which user fix on map.

Start/Stop AVD:-
                         1.  using Telnet you can start/stop avd(android virtual device).

                         Example:- avd start 5556
                                         avd start 5558

                         2. Load/delete snapshot of avd.

                         Example:- avd snapshot save 5554
                                         avd snapshot del 5554

Manage Network:-
                                Example:- network status
                                                network capture start

You can also able to do lot of work which Telnet offer. Go and play on Telnet.




Thank you....
Save Tree Save Life


            
            

Architecture of Android

Introduction:-
Android is a software platform for mobile devices based n Linux operating system and developed by
 Google and Open Handset Alliance.

Android Features:-
                     - Android architecture enabling developers to reuse and replacement of existing
 component .  
                     -provide SQLite for data storage .                                                                                         
                     -Great media support(JPEG,GIF,PNG,AMR,MP3,MPEG4) .                                               
                     -Network support(Bluetooth,Wi-Fi,EDGE,3G) .                                                                    
                     -Hardware support(Camera,GPS,Compass,Accelerometer).
                     -Powerful SDK                                                  
   

Architecture:-  
                     The following diagram shows Architecture of Android.


Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.
Android allow developers to make a powerful and innovative application.


Application Framework:-
                    Android will ship with a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, and others. All applications are written using the Java programming language.

Linux Kernel:-
                           Android relies on Linux version 2.6.

 
                       - Core System Services:-
                                  -Security Management.
                                  -Process Management.
                                  -Memory Management.
                                  -Driver Model.
                                  -Network Stack

 Libraries:-
                 -Android include a set of C/C++ Libraries.        
                                                                         

                 -Some other are.
                       -System C Library.
                       -Media Libraries.
                       -SGL.
                       -3D Libraries.
                       -FreeType.
                       -SQLite.


Thank you....

Save Tree Save Life

String Tokenizer


String Tokenizer:-

Using StringTokenizer you can easily Split String into Tokens.
We can use StringTokenizer using following method;-
StringTokenizer(String str)
StringTokenizer(String str, String delimiters)  
 
Here is simple Example.

 StringTokenizer strTo = new StringTokenizer("x-y-z", "-");
 while (st.hasMoreTokens()) 
 {
     System.out.println(st.nextToken());
 }
Another way:-
 for (String token : "x-y-z".split("-")) 
 {
     System.out.println(token);
 }

Simple java Example:-

public class Test {
public static void main(String[] args) {
    String str="this is=android{welcome}";
    StringTokenizer st = new StringTokenizer(str,"={}");

    System.out.println("---- Split by sp");
    while (st.hasMoreElements()) {
        String profile=st.nextElement().toString();
        String name=st.nextElement().toString();
        System.out.println("profile="+ profile +"name="+ name);
    }

    System.out.println("---- Split by comma ',' ------");
    StringTokenizer st2 = new StringTokenizer(str, ",");

    while (st2.hasMoreElements())
    {
        System.out.println(st2.nextElement());
    }
   
}
}
o/p:-
---- Split by sp
profile=this,is
name=android
other=welcome

---- Split by comma ',' ------
this
is=android{welcome}
Explanation:-

1> public int countTokens ()

Returns the number of unprocessed tokens remaining in the string.
Returns:-
number of tokens that can be retreived before an Exception will result from a call to nextToken().

2>public boolean hasMoreElements ()

Returns
  • true if unprocessed tokens remain.

3>public boolean hasMoreTokens ()

Returns
  • true if unprocessed tokens remain.

4>public Object nextElement ()

Returns the next token in the string as an Object. This method is implemented in order to satisfy the Enumeration interface.
Returns:-
next token in the string as an Object
Throws:-
NoSuchElementExceptionif no tokens remain.

5>public String nextToken (string delims)


Returns the next token in the string as a String. The delimiters used are changed to the specified delimiters.
Parameters:-
delims the new delimiters to use.
Returns
  • next token in the string as a String.
Throws
NoSuchElementExceptionif no tokens remain. 






























Thank you.. Suggestion Appreciated..