mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-17 13:17:33 +01:00
Use TelephonyManager getCallState() instead of the provided extras
According to the documentation the current call state might be not correctly contained in the extra, and using getCallState() is the right thing to do Might help for #799 (and #756)
This commit is contained in:
parent
3b25181a32
commit
d109630e74
@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|||||||
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.NotificationManager.Policy;
|
import android.app.NotificationManager.Policy;
|
||||||
|
import android.app.Service;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -35,19 +36,12 @@ public class PhoneCallReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
|
||||||
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
|
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
|
||||||
mSavedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
|
mSavedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
|
||||||
} else {
|
} else {
|
||||||
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
|
|
||||||
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
|
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
|
||||||
int state = 0;
|
int state = tm.getCallState();
|
||||||
if (TelephonyManager.EXTRA_STATE_IDLE.equals(stateStr)) {
|
|
||||||
state = TelephonyManager.CALL_STATE_IDLE;
|
|
||||||
} else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(stateStr)) {
|
|
||||||
state = TelephonyManager.CALL_STATE_OFFHOOK;
|
|
||||||
} else if (TelephonyManager.EXTRA_STATE_RINGING.equals(stateStr)) {
|
|
||||||
state = TelephonyManager.CALL_STATE_RINGING;
|
|
||||||
}
|
|
||||||
onCallStateChanged(context, state, number);
|
onCallStateChanged(context, state, number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user