简体   繁体   中英

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.

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(); } } } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM