Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
- Log.v("ranjith", "Entered in callstatelistener");
- <!-- declare the permission -->
- <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" >
- <!-- Register your Broadcast receiver -->
- <receiver android:name=".CallReceiver" android:enabled="true">
- <intent-filter>
- <action android:name="android.intent.action.PHONE_STATE" />
- </intent-filter>
- </receiver>
- </application>
- public class CallReceiver extends BroadcastReceiver {
- static boolean isRinging = false;
- static boolean isCallReceived = false;
- @Override
- public void onReceive(Context context, Intent intent) {
- // TODO Auto-generated method stub
- // Get the current Phone State
- String phoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
- if(phoneState == null)
- return;
- // If phone is "Rininging"
- if(phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING))
- {
- isRinging = true;
- }
- // If an incoming call is received
- if(phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
- {
- isCallReceived = true;
- }
- // if phone is idle
- if (phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)){
- // detect call not received
- if(isRinging == true && isCallReceived == false){
- Toast.makeText(context, "Call was not received!", Toast.LENGTH_LONG).show();
- }
- }
- }
Add Comment
Please, Sign In to add comment