I am working on an Application where i need to detect incoming call in activity's onResume(), i am using this code to detect any incoming call.
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener callStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber)
{
if(state==TelephonyManager.CALL_STATE_RINGING){
// Code
}
}
};
telephonyManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE);
Moreover it's working on every device below Oreo, and on Oreo device its not working, i am not sure where i am doing wrong
Make a broadcast receiver and declare it in the manifest file, if you need it to work even when the app is not ON, otherwise make a broadcast receiver in the activity, to make your app listen to calls(not literally listen, I think you know what I am saying). When you create it, just type registerReceiver(...fill your intent filters, etc here...) in onCreate function and unregisterReceiver() in onDestroy() to finish it before closing the activity