应用关闭后如何继续启动Broadcast Receiver Evan

问题描述

public class PhoneStateReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context,Intent intent) {
    method(context,intent);
}

private void method(Context context,Intent intent) {
    Utils.printLog("PhoneStateReceiver","");

    TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(new PhoneStateListenerCustom(),PhoneStateListener.LISTEN_CALL_STATE);
    Bundle bundle = intent.getExtras();
    String phone_number = bundle.getString("incoming_number");

    if (telephony.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
        Utils.printLog("CALL_STATE_IDLE","");

    } else if (telephony.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK) {
        Utils.printLog("CALL_STATE_OFFHOOK","");


    } else if (telephony.getCallState() == TelephonyManager.CALL_STATE_RINGING) {
        Utils.printLog("CALL_STATE_RINGING","");
    }
}

private class PhoneStateListenerCustom extends PhoneStateListener {
    public void onCallStateChange(int state,String incomingNumber) {
        System.out.println("Icoming Number inside onCallStateChange : " + incomingNumber);
        switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                System.out.println("PHONE RINGING.........TAKE IT.........");
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                System.out.println("CALL_STATE_OFFHOOK...........");
                break;
        }
    }
}

}

这是我的代码,我想在关闭应用程序后继续我的广播接收器Evan,我的广播接收器的主要用途是检测带有电话号码的来电,这是不可能的。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)