Tuesday, May 28, 2013

Incoming Call Reciever In Android


Learn Android Development


In previous I discussed about how to handle incoming call or how to listen for Incoming call using Activity, In this post I will discuss the same using Broadcast Receiver.

Broadcast Receiver is  better way than Activity to listen for Incoming Calls.

So declare the Permission and Receiver in Manifest

Permission Required:

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

Declare the receiver and register it to listen "android.intent.action.PHONE_STATE"  action

android.manifest 


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.incomingcallreciever"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
   
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
       
       
        <receiver android:name=".IncommingCallReceiver" android:enabled="true">
            <intent-filter>
                                     <action android:name="android.intent.action.PHONE_STATE" />
                </intent-filter>
           </receiver>

    </application>

</manifest>







Incoming Call Receiver




import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.widget.Toast;


 public class IncommingCallReceiver extends BroadcastReceiver
 {
   
      Context mContext;
     
     
      @Override
      public void onReceive(Context mContext, Intent intent)
      {
          try
          {
          
              String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

          
           
              if(state.equals(TelephonyManager.EXTRA_STATE_RINGING))
              {
                   Toast.makeText(mContext, "Phone Is Ringing", Toast.LENGTH_LONG).show();
                   // Your Code
              }
             
              if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
              {
                   Toast.makeText(mContext, "Call Recieved", Toast.LENGTH_LONG).show();
                       // Your Code
              }
             
              if (state.equals(TelephonyManager.EXTRA_STATE_IDLE))
              {
               
                  Toast.makeText(mContext, "Phone Is Idle", Toast.LENGTH_LONG).show();
                      // Your Code
               
              }
          }
          catch(Exception e)
          {
              //your custom message
          }
      
     }
     
}






     
     
   

 

 

 

Advance Android Topics


                   Customizing Toast In Android 
                   Showing Toast for Longer Time
                   Customizing the Display Time of Toast
                   Using TimePickerDialog and DatePickerDialog In android
                   Animating A Button In Android
                    Populating ListView With DataBase

                    Customizing Checkboxes In Android 
                    Increasin Size of Checkboxes
                    Android ProgressBar
                    Designing For Different Screen Sizes
                    Handling Keyboard Events 



More Android Topics:



Android : Introduction


       Eclipse Setup for Android Development

                     Configuring Eclipse for Android Development

          Begging With Android

                     Creating Your First Android Project
                     Understanding Android Manifest File of your android app


         Working With Layouts

                      Understanding Layouts in Android
                          Working with Linear Layout (With Example)
                                Nested Linear Layout (With Example)
                          Table Layout
                          Frame Layout(With Example)
                         Absolute Layout
                         Grid Layout


       Activity

                     Activity In Android
                     Activity Life Cycle
                     Starting Activity For Result
                     Sending Data from One Activity to Other in Android
                     Returning Result from Activity

     Working With Views

                     Using Buttons and EditText in Android 
                     Using CheckBoxes in Android 
                     Using AutoCompleteTextView in Android
                     Grid View

       Toast

                     Customizing Toast In Android
                     Customizing the Display Time of Toast
                     Customizing Toast At Runtime
                     Adding Image in Toast
                     Showing Toast for Longer Time

     Dialogs In Android

                     Working With Alert Dialog
                     Adding Radio Buttons In Dialog
                     Adding Check Boxes In Dialog
                     Creating Customized Dialogs in Android
                    Adding EditText in Dialog

                   Creating Dialog To Collect User Input

                 DatePicker and TimePickerDialog

                              Using TimePickerDialog and DatePickerDialog In android

    Working With SMS

                  How to Send SMS in Android
                  How To Receive SMS
                  Accessing Inbox In Android

    ListView:

               Populating ListView With DataBase

      Menus In Android

                    Creating Option Menu
                    Creating Context Menu In Android

      TelephonyManager

                    Using Telephony Manager In Android

     Working With Incoming Calls

                    How To Handle Incoming Calls in Android
                    How to Forward an Incoming Call In Android
                   CALL States In Android
 

    Miscellaneous

                   Notifications In Android
                   How To Vibrate The Android Phone
                   Sending Email In Android
                  Opening a webpage In Browser
                   How to Access PhoneBook In Android
                   Prompt User Input with an AlertDialog

   Storage:  Storing Data In Android


               Shared Prefferences  In Android

                             SharedPreferences In Android

               Files: File Handling In Android

                              Reading and Writing files to Internal Stoarage
                              Reading and Writing files to SD Card 
                           

                DataBase : Working With Database

                             Working With Database in Android
                             Creating Table In Android
                             Inserting, Deleting and Updating Records In Table in Android
                             How to Create DataBase in Android
                             Accessing Inbox In Android

     Animation In Android:

                  Animating A Button In Android



16 comments:

  1. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    Android training|Android Training in Chennai|Best ios training in chennai

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. Very easily this site will most likely irrefutably perhaps end up being popular including numerous weblogs individuals, in order to it's persistent content pieces or possibly views. Customer Support Outsourcing

    ReplyDelete
  5. This is a fantastic website and I can not recommend you guys enough. I really appreciate your post.AWS course in Chennai

    ReplyDelete
  6. I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. hanumanchalisalyrics

    ReplyDelete
  7. Effectually composed data. it will probably be helpful to us all who utilizes it, comprising of me. continue to happen the sort produce results. For specific I will look at additional posts. This website page appears to income a tomfoolery measure of traffic.. Microsoft Office 2019 Crack

    ReplyDelete
  8. This exact is by and large evidently stinky and close by fantastic convincing along at the rear of without a doubt legit disapproved what's more as a matter of fact helpful My impact is trying to view as in front assumed for this remarkable valuable stuffs. Windows 10 Crack

    ReplyDelete
  9. I can see this page and read it that's great.
    https://crackpcstore.com/quick-batch-file-compiler-crack-download/

    ReplyDelete
  10. post... thanks For Sharing !!Great information for new guy like Bhagwat Geeta in Hindi PDF

    ReplyDelete
  11. post... thanks For Sharing !!Great information for new guy like anuvad kise kahate hain

    ReplyDelete