PhoneBroadcast.java
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.lotus.town.broadcast;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.widget.Toast;
import com.controller.NotifyType;
import com.lotus.town.ali.MonitorService;
import com.lotus.town.notify.NotifyManager;
import com.sdk.Debug;
import com.sdk.EventBus;
public class PhoneBroadcast extends BroadcastReceiver {
private TelephonyManager telMgr;
@Override
public void onReceive(Context context, Intent intent) {
telMgr = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
switch (telMgr.getCallState()) {
//来电
case TelephonyManager.CALL_STATE_RINGING:
NotifyManager.PhoneStartTime = System.currentTimeMillis();
NotifyManager.isPhoneStatus = true;
EventBus.getInstance().notify(EventBus.PHONE_COMING);
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
MonitorService.invoke(context);
break;
//响铃
case TelephonyManager.CALL_STATE_OFFHOOK:
NotifyManager.isPhoneStatus = true;
NotifyManager.PhoneStartTime = System.currentTimeMillis();
EventBus.getInstance().notify(EventBus.PHONE_COMING);
if(Debug.DEBUG_MODE) {
Toast.makeText(context, "响铃", Toast.LENGTH_LONG).show();
}
break;
//挂断
case TelephonyManager.CALL_STATE_IDLE:
NotifyManager.isPhoneStatus = false;
NotifyManager.PhoneEndTime = System.currentTimeMillis();
if(Debug.DEBUG_MODE) {
Toast.makeText(context, "挂电话", Toast.LENGTH_LONG).show();
}
NotifyManager.NotifyChange(context, NotifyType.PHONE_OVER_NOTIRY);
MonitorService.invoke(context);
break;
}
}
}