Monday, 16 April 2012

DEVELOPING BLACKLIST ANDROID APP...



This Blog is about my first android application and my future plan with android...


Problem Statement :

To block the unwanted calls. Whenever someone who has been blacklisted will try to call you , he/she will get the message that you are busy but in actuality that number is blocked by you.

Design:

The development of the app has commenced in three steps:

1.Development of UI.
2.Creation of an explicit Database for storing the blacklisted number and querying the Database      whenever required. 
3.Use of Telephony Manager Class to access information about the telephony service on the device.

Development of UI : User Interface is built using View and ViewGroup object. A View object is a data structure whose properties and content for a specific rectangular area of the screen. A View object handles its own measurement, layout, drawing, focus change, scrolling, and key/gesture interaction for the rectangular area of the screen in which it resides.
           The most common way to define layout and express View hierarchy is with an XML layout file.I have created main.xml file which will create an UI having facilities like inserting, deleting, searching the name and number . One more button is provided to view the list of all blacklisted name and number. The Graphical layout of the user interface is shown in the figure below,
                                                           Fig: 1 Graphical view of UI

Creation of Database : The application is designed by using many java classes and one main activity. The main activity is BlackActivity.java and is the starting point of the app. The two other Java file (DatabaseOpenHelper.java and DatabaseAdapter.java ),   DatabaseOpenHelper.java extends SQliteOpenHelper class and override the Oncreate method to create a Database and then creating table inside database, the code is here


public void onCreate(SQLiteDatabase sqLiteDB) {
// TODO Auto-generated method stub
String createSql = "CREATE TABLE piyush " +
            "(name text not null, "+"number text primary key);";
    sqLiteDB.execSQL(createSql);


}



DatabaseAdapter.java consist of Five methods (Open, Close, CreateRecord, DeleteRecord, FetchRecord) which helps in manipulation of database. First this class create an instance of  DatabaseOpenHelper class.  These all methods can be accessed from main activity by creating instance of DatabaseAdapter class and User Interface will be linked with the database by parsing XML file via R.java file. Just like an example code below,  


DatabaseAdapter databaseAdapter = new DatabaseAdapter(getApplicationContext());


 Button button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener() {            
            public void onClick(View v) {
             t1 = (EditText) findViewById(R.id.editText1);
                t2 = (EditText) findViewById(R.id.editText2);
                DatabaseAdapter databaseAdapter = new DatabaseAdapter(getApplicationContext());
                databaseAdapter.open();
                databaseAdapter.createRecord(t1.getText().toString(),t2.getText().toString());
                Toast.makeText(getBaseContext(), "insertion done", 5).show();
                databaseAdapter.close();
            }
        });




Use of Telephony Manager Class : The main work of the app is done here, basically there are three call state ( Ringing, Idle, Off_Hook). My app mainly uses Ringing State, whenever device receive any call , it switch to the Ringing state . Now my work is to end the call as it switches to ringing state and send some message to the caller. I basically created a class (StateListener) in the main activity which extend PhoneStateListenerclass, and override the onCallStateChanged() method.
An interface file (ITelephony.java) is created to use the already available method to end the call. Code is below


package com.android.internal.telephony;


public interface ITelephony {
 boolean endCall();
         void answerRingingCall();
         void silenceRinger();
}


Now , I created an instance of TelephonyManager class and called the Listen() method to listen everytime for any change in the state. whenever any change in the state is detected, onCallStateChanged() is called. If the changed state is Ringing ,then endcall() method is called.
Some permissions need to be updated in the manifest file.

                                                  Fig 2 : File Structure of my project in Eclipse 


Conclusion : 


By Developing this application,I have learnt about basics of Android app design, implementing in java programming language and object oriented approach, Introduction to User Interface Design. Finally my app is working.


Future Plans : Android application development is rapidly increasing with its developer base growing day by day. I  want to be a successful part of this development. As per my first application is concerned , i want to add one more feature of Time Constraint in my app, i mean the caller will be blocked only for some specific time as specified by the receiver. 


Credits:Mr.Vinod Pathari


Note:-If any one desires to get the complete source code then he/she may contact at the following e-mail address.
anmolprakashnitc@gmail.com