Skip to content

Commit

Permalink
Improve state receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpandey committed Dec 9, 2022
1 parent 971d76d commit 018fcfd
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ public class DynamicStateReceiver extends BroadcastReceiver {

@Override
public void onReceive(@NonNull Context context, @Nullable Intent intent) {
if (intent != null
&& TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(intent.getAction())) {
if (intent == null || intent.getAction() == null) {
return;
}

if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(intent.getAction())) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

if (state != null && (state.equals(TelephonyManager.EXTRA_STATE_RINGING)
|| state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))) {
if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)
|| TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) {
context.sendBroadcast(new Intent(DynamicEngineUtils.ACTION_ON_CALL));
} else {
context.sendBroadcast(new Intent(DynamicEngineUtils.ACTION_CALL_IDLE));
Expand Down

0 comments on commit 018fcfd

Please sign in to comment.