Missed call alert in android

Missed call alert in Android Programmatically

This Missed call alert android example alert tutorial is very useful to find the missed calls with numbers. From that you can get missed call notification via sms.

Follow the simple steps to create this app,
  1. First, you have set the Receiver for receive the CALLS.
  2. In receiver create Intent-filter with “android.intent.action.PHONE_STATE” action.
    <receiver android:name="com.rajaappstore.missedcallalert.MainActivity">
    <intent-filter>
       <action android:name="android.intent.action.PHONE_STATE"></action>
    </intent-filter>
    </receiver>
  3. In MainActivity extends BroadcastReceiver for receiver intent-filter action. Then, Create object for the TelephonyManager.
    TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  4. Register PhoneStateListener with the TelephonyManager.

    CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();
    telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
  5. Finally,You have to check wether the incoming call is missed or answered by the user under the PhoneStateListener using the TelephonyManager.
    case TelephonyManager.CALL_STATE_IDLE:
    if((prev_state==TelephonyManager.CALL_STATE_OFFHOOK)){
    prev_state=state;
    //call answered
    }
    if((prev_state==TelephonyManager.CALL_STATE_RINGING)){
    prev_state=state;
    //call missed or rejected
    }
    break;
  6. Then, You can create SMS with the missed call number to the another user using the SmsManager.

    SmsManager sms= SmsManager.getDefault();
    sms.sendTextMessage("5556", null, "Missed call from"+incomingNumber, nullnull);
Don’t forget to add Permissions,
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />

Final, MainActivity.java

public class MainActivity extends BroadcastReceiver { 
 
 private static final String TAG = "BroadcastReceiver"; 
 Context mContext; 
 String incoming_nr; 
 private int prev_state; 
 @Override 
 public void onReceive(Context context, Intent intent) { 
 TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); //TelephonyManager object 
 CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener(); 
 telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); //Register our listener with TelephonyManager 
 Bundle bundle = intent.getExtras(); 
 String phoneNr= bundle.getString("incoming_number"); 
 Log.v(TAG, "phoneNr: "+phoneNr); 
 mContext=context; 
 } 
 /* Custom PhoneStateListener */ 
 public class CustomPhoneStateListener extends PhoneStateListener { 
 
 private static final String TAG = "CustomPhoneStateListener"; 
 
 @Override 
 public void onCallStateChanged(int state, String incomingNumber){ 
 
 if(incomingNumber!=null&&incomingNumber.length()>0) incoming_nr=incomingNumber; 
 switch(state){ 
 case TelephonyManager.CALL_STATE_RINGING: 
 Log.d(TAG, "CALL_STATE_RINGING"); 
 prev_state=state; 
 break; 
 case TelephonyManager.CALL_STATE_OFFHOOK: 
 Log.d(TAG, "CALL_STATE_OFFHOOK"); 
 prev_state=state; 
 break; 
 case TelephonyManager.CALL_STATE_IDLE: 
 Log.d(TAG, "CALL_STATE_IDLE==>"+incoming_nr); 
 if((prev_state==TelephonyManager.CALL_STATE_OFFHOOK)){ 
 prev_state=state; 
 //Answered Call which is ended
 Toast.makeText(mContext, "answered call end", 5).show();
 } 
 if((prev_state==TelephonyManager.CALL_STATE_RINGING)){ 
 prev_state=state; 
 //Rejected or Missed call 
 Toast.makeText(mContext, " missed call end"+incomingNumber, 5).show();
 SmsManager sms=SmsManager.getDefault();
 sms.sendTextMessage("5554", null, "Missed call from"+incomingNumber, null, null);
 
 } 
 break; 
 } 
 } 
 } 
}
velmm download code

3 thoughts on - Missed call alert in android

    • Thanks

  • thanks a lot you have made a great effort to write the article now i am very happy that u can use the service in my mobile it self
    missed call service in india

Leave a Reply

Your email address will not be published. Required fields are marked *