package com.bw.day13i;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
public class MySystemService extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.intent.action.AIRPLANE_MODE"))
{
Bundle bundle = intent.getExtras();
boolean state = bundle.getBoolean("state");
if (state){
Toast.makeText(context, "开启飞行模式", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "关闭飞行模式", Toast.LENGTH_SHORT).show();
}
Log.i("---ccc", "onReceive: "+"飞行模式");
}
if (intent.getAction().equals("android.intent.action.PHONE_STATE")){
@SuppressLint("ServiceCast") TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELECOM_SERVICE);
int callState = telephonyManager.getCallState();
switch (callState){
case TelephonyManager.CALL_STATE_RINGING:
Log.i("--ss", "onReceive: "+"打电话");
break;
case TelephonyManager.CALL_STATE_IDLE:
Log.i("--ss", "onReceive: "+"结束电话");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.i("--ss", "onReceive: "+"正在电话");
break;
}
}
}
}