Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.joythis.android.myphonecaller;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.telephony.TelephonyManager;
- import android.widget.Toast;
- public class MyReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- String strState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
- // ringing, idle, offhook
- boolean bRinging = strState.equals(TelephonyManager.EXTRA_STATE_RINGING);
- boolean bIdle = strState.equals(TelephonyManager.EXTRA_STATE_IDLE);
- boolean bOffhook = strState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK);
- if(bRinging){
- Toast.makeText(context, "RINGING!", Toast.LENGTH_LONG).show();
- }
- if(bIdle){
- Toast.makeText(context, "IDLE", Toast.LENGTH_LONG).show();
- }
- if(bOffhook){
- Toast.makeText(context, "OFFHOOK", Toast.LENGTH_LONG).show();
- }
- }//onReceive
- }//MyReceiver
Advertisement
Add Comment
Please, Sign In to add comment