老人机轮询紧急拨号功能

android 专栏收录该内容
58 篇文章 1 订阅


1.介绍:该功能主要为老人机做的,方便一键拨打紧急联系人号码:

主要功能:1.管理紧急联系人号码,添加,修改,删除

                  2.触发倒计时拨打紧急号码

                  3.轮询拨打添加的紧急号码直到拨通一个号码

                  4.紧急号码联系人发送特定短信功能:1.发送定位,2.自动解锁,3.自动拨打紧急号码


主要功能图片如下:

              


我今天要介绍的是如何实现倒计时轮询拨打紧急号码功能,其它像号码管理和UI界面就不做介绍。



2.倒计时拨号,现在是倒计时5秒后开始拨号

public class EmergencyCountTimeActivity extends Activity {
private static final int START_COUNTING = 1;
private static final int COUNT_NUMBER = 5;
private Button cancel;
private TextView mCountDown;
private MyHandler mHandler = new MyHandler();
private boolean cancelDial = false;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initData();
if (simIsExist()) {//判断SIM卡是否存在
if(followList.size() <= 0){//判断是否有添加紧急号码
setFinishOnTouchOutside(false);
setContentView(R.layout.emergency_no_sim_hint);
mCountDown = (TextView) findViewById(R.id.count_text);
mCountDown.setText(this.getString(R.string.emergency_please_add_hint));
sleepFinish(2000,true);
}else{
setContentView(R.layout.emergency_count_down_time);
init();
}
} else {
setFinishOnTouchOutside(true);
setContentView(R.layout.emergency_no_sim_hint);
mCountDown = (TextView) findViewById(R.id.count_text);
sleepFinish(3000,false);
}
initWindow();
}


private void sleepFinish(int n,final boolean isFinish) {
TimerTask task = new TimerTask() {
@Override
public void run() {
if(isFinish){
Intent intent = new Intent(EmergencyCountTimeActivity.this,EmergencyConatctSettingsActivity.class);
startActivity(intent);
}
EmergencyCountTimeActivity.this.finish();
}
};
Timer timer = new Timer();
timer.schedule(task, n);// 3秒后执行TimeTask的run方法

}


/*
* 判断SIM卡
*/
private boolean simIsExist() {
boolean isExist = false;
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String simSer = tm.getSimSerialNumber();
if (simSer == null || simSer.equals("")) {
isExist = false;
} else {
isExist = true;
}
return isExist;
}


/*
*初始化当前窗口显示位置
*/
private void initWindow() {
android.view.WindowManager.LayoutParams p = getWindow().getAttributes();
p.width = ViewGroup.LayoutParams.MATCH_PARENT;
p.height = ViewGroup.LayoutParams.WRAP_CONTENT;
p.gravity = Gravity.BOTTOM;
p.dimAmount = 0.5f;
getWindow().setAttributes(p);
}


private void init() {
cancel = (Button) findViewById(R.id.cancel);
mCountDown = (TextView) findViewById(R.id.count_text);
Message msg = mHandler.obtainMessage();
msg.what = START_COUNTING;//
msg.obj = COUNT_NUMBER;
mHandler.sendMessageDelayed(msg, 100);
cancel.setOnClickListener(new OnClickListener(){//取消倒计时拨打电话


@Override
public void onClick(View v) {
// TODO Auto-generated method stub
EmergencyCountTimeActivity.this.finish();
cancelDial = true;
}

});

}


private class MyHandler extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);


switch (msg.what) {
case START_COUNTING:
int count = (int) msg.obj;
mCountDown.setText(count + "");
if (count > 0) {//倒计时大于0
Message msg1 = obtainMessage();
msg1.what = START_COUNTING;
msg1.obj = count - 1;
if(!cancelDial){
sendMessageDelayed(msg1, 1000);
}
} else {
startDial();//开始拨号
}
break;


default:
break;
}
}
};


private ArrayList<EmergencyModel> followList = new ArrayList<EmergencyModel>();


/*
* 获取急救号码
*/
private void initData() {


EmergencyModel tmp;
String ids = EmergencyUtil.getAllId(this);
if (ids != null) {
String[] array = ids.split(EmergencyConatctSettingsActivity.Splite);
for (int n = 0; n < array.length; n++) {
tmp = EmergencyUtil.readObject(this, array[n]);
if (tmp != null) {
followList.add(tmp);
}
}
}
}


/*
* 开始拨打紧急号码
*/
public void startDial() {
if (followList.size() > 0) {
Intent intent = new Intent(Intent.ACTION_CALL);
Uri data = Uri.parse("tel:" + followList.get(0).getNumber());
intent.setData(data);
startActivity(intent);
if(followList.size() > 1){
followList.remove(0);
InCallPresenter.getInstance().setEmergencyList(followList);
}
this.finish();
} else {

setFinishOnTouchOutside(true);
setContentView(R.layout.emergency_no_sim_hint);
mCountDown.setText(this.getString(R.string.emergency_please_add_hint));
sleepFinish(2000,true);
}
}


}

3.轮询拨号在IncallUi中实现具体实现代码InCallPresenter.java类onCallListChange方法中实现

 轮询拨号逻辑:


  if(cancelEmergency){
        if(mHasAnswered){
        cancelEmergency = false;
        }else if(newState != InCallState.OUTGOING && newState != InCallState.PENDING_OUTGOING){
          if(followList.size() > 0){
        Intent intent = new Intent(Intent.ACTION_CALL);
        Uri data = Uri.parse("tel:" + followList.get(0).getNumber());
        intent.setData(data);
        mContext.startActivity(intent);
        followList.remove(0);
        }else{
        cancelEmergency = false;
        }
            }
        }

  • 0
    点赞
  • 4
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值