1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-08 22:51:37 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/PhoneCallReceiver.java
Andreas Shimokawa bf6abe9672 Quick and dirty support for incoming calls notification the Pebble way
Incoming calls are no longer send as simple notifications but properly as
incoming calls. The Pebble will vibrate until the call is taken or dismissed.

It is not yet possible to dismiss the call using the Pebble button.
2015-01-22 22:49:50 +01:00

30 lines
1.3 KiB
Java

package nodomain.freeyourgadget.gadgetbridge;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public class PhoneCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String phoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
byte state = 0;
if (phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
state = PebbleProtocol.PHONECONTROL_INCOMINGCALL;
} else if (phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE) || phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
state = PebbleProtocol.PHONECONTROL_END;
}
if (state != 0) {
String phoneNumber = intent.hasExtra(TelephonyManager.EXTRA_INCOMING_NUMBER) ? intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER) : "";
Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
startIntent.setAction(BluetoothCommunicationService.ACTION_INCOMINGCALL);
startIntent.putExtra("incomingcall_phonenumber", phoneNumber);
startIntent.putExtra("incomingcall_state", state);
context.startService(startIntent);
}
}
}