Skip to main content

Android Call State BroadCastReceiver Example

Android Call State BroadCastReceiver Example

activity_main.xml

File: activity_main.xml
  1. <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context=".MainActivity" >  
  10.   
  11.     <TextView  
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="wrap_content"  
  14.         android:text="@string/hello_world" />  
  15.   
  16. </RelativeLayout>  

Activity class

File: MainActivity.java
  1. package com.example.callstatebroadcastreceiver;  
  2.   
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.view.Menu;  
  6.   
  7. public class MainActivity extends Activity {  
  8.   
  9.     @Override  
  10.     protected void onCreate(Bundle savedInstanceState) {  
  11.         super.onCreate(savedInstanceState);  
  12.         setContentView(R.layout.activity_main);  
  13.     }  
  14.   
  15.   
  16.     @Override  
  17.     public boolean onCreateOptionsMenu(Menu menu) {  
  18.         // Inflate the menu; this adds items to the action bar if it is present.  
  19.         getMenuInflater().inflate(R.menu.main, menu);  
  20.         return true;  
  21.     }  
  22.       
  23. }  

IncommingCallReceiver

File: IncommingCallReceiver.java
  1. package com.example.callstatebroadcastreceiver;  
  2.   
  3. import android.content.BroadcastReceiver;  
  4. import android.content.Context;  
  5. import android.content.Intent;  
  6. import android.telephony.TelephonyManager;  
  7. import android.widget.Toast;  
  8.   
  9.   
  10.  public class IncommingCallReceiver extends BroadcastReceiver{  
  11.       Context context;  
  12.          
  13.       @Override  
  14.       public void onReceive(Context context, Intent intent){  
  15.           try{  
  16.            String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);  
  17.   
  18.               if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){  
  19.                    Toast.makeText(context, "Phone Is Ringing", Toast.LENGTH_LONG).show();  
  20.               }  
  21.                 
  22.               if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){  
  23.                    Toast.makeText(context, "Call Recieved", Toast.LENGTH_LONG).show();  
  24.               }  
  25.                 
  26.               if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){  
  27.                    Toast.makeText(context, "Phone Is Idle", Toast.LENGTH_LONG).show();  
  28.               }  
  29.           }  
  30.           catch(Exception e){e.printStackTrace();}  
  31.       }  
  32.         
  33. }  

Comments

Popular posts from this blog

Inverted Linear Quadtree: Efficient Top K Spatial Keyword Search

Inverted Linear Quadtree: Efficient Top K Spatial Keyword Search ABSTRACT: In this paper, With advances in geo-positioning technologies and geo-location services, there are a rapidly growing amount of spatiotextual objects collected in many applications such as location based services and social networks, in which an object is described by its spatial location and a set of keywords (terms). Consequently, the study of spatial keyword search which explores both location and textual description of the objects has attracted great attention from the commercial organizations and research communities. In the paper, we study two fundamental problems in the spatial keyword queries: top k spatial keyword search (TOPK-SK), and batch top k spatial keyword search (BTOPK-SK). Given a set of spatio-textual objects, a query location and a set of query keywords, the TOPK-SK retrieves the closest k objects each of which contains all keywords in the query. BTOPK-SK is the batch processing of sets...

A simple and reliable touch sensitive security system CODING

#include <REGX51.H> #include "lcd.c" #define MAX_DELAY() delay(65000) sbit Vibra_Sense=P3^1; sbit Buz=P1^0; void intro() {  lcd_init();  lcd_str("Touch Sensitive ",0x80);  lcd_str("Security System ",0xc0);  MAX_DELAY();MAX_DELAY();  lcd_clr();  }  void main()  { unsigned int i = 0, j= 0; intro();    while(1)    { lcd_str("Security Syst On",0x80); lcd_str("No Vibra Detectd",0xc0); Buz = 1; if(Vibra_Sense == 1) { while(Vibra_Sense == 1) delay(1000); } else { while(Vibra_Sense == 0) delay(1000); } Buz = 0; lcd_str("Vibraton Detectd",0xc0);delay(65000); while(1);    }  }

A Time Efficient Approach for Detecting Errors in Big Sensor Data on Cloud

A Time Efficient Approach for Detecting Errors in Big Sensor Data on Cloud Abstract                                                                                                                                                      ...