Atendra Singh
Atendra Singh

Reputation: 396

How to get incoming calls when app is in kill state in Android with Twilio SDK?

I am trying to implement Twilio SDK and i have done it, It is working fine when APP is in memory not killed.. Now I have to implement Twilio to get calls any time if my app is is killed or not. How can i achieve this like by any service in background or any other solution. Thanks in advance.

Upvotes: 2

Views: 1070

Answers (1)

Gulnaz Ghanchi
Gulnaz Ghanchi

Reputation: 485

I have not worked with twillo api, but you can achieve events of calling from android system using following code. You should try this out.

To register Broadcast Receiver, write below codes in AndroidMainifest.xml file.

<receiver android:name=".PhoneStateReceiver">
  <intent-filter>
    <action android:name="android.intent.action.PHONE_STATE" />
  </intent-filter> 
</receiver>

to give phone state permission to your app use below code in your AndroidManifest.xml file

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

Below is Broadcast Receiver

public class PhoneStateReciver extends BroadcastReceiver {


  public void onReceive(Context context, Intent intent) {
    try 
     {
        System.out.println("Receiver start");
        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
         if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){   
          Toast.makeText(context,"Ringing State Number is -"+incomingNumber,Toast.LENGTH_SHORT).show(); 
        } 
        if ((state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))){
          Toast.makeText(context,"Received State",Toast.LENGTH_SHORT).show();
        } 
        if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
          Toast.makeText(context,"Idle State",Toast.LENGTH_SHORT).show();
        } 
    }catch (Exception e){ 
      e.printStackTrace(); 
    } 
  } 

}

Upvotes: 2

Related Questions