当incoming_Sip呼叫和应答时唤醒设备

时间:2014-05-28 13:21:57

标签: android broadcastreceiver sip

当应用程序仍处于后台时,窗口标记效果很好,能够唤醒屏幕并触发InComingCallActivity接收SipCalls。

我的问题是如何在用户关闭应用程序时唤醒设备,并在应用程序仍处于后台时(即当BroadcastReceiver唤醒设备收到来电事件时实现相同功能)触发相应的意图)。以下是唤醒设备的正确方法并打开Intent.Please帮助!

    Window window = this.getWindow();
    window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
    window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);

以下是我IncomingCallReceiver的代码 - 我在这个课程中呼叫InComingCallActivity来接听和拒绝来电。

public class IncomingCallReceiver extends BroadcastReceiver {
/**
 * Processes the incoming call, answers it, and hands it over to the IncommingCallActivity.
 * 
 * @param context
 *            The context under which the receiver is running.
 * @param intent
 *            The intent being received.
 */
String userName = null;
public SipAudioCall incomingCall = null;
SessionManager sessionManager = SessionManager.getSessionInstance();

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

    SipAudioCall incomingCall = null;
    // sipReg = new SipRegisteration(context);

    try {
        SipAudioCall.Listener listener = new SipAudioCall.Listener() {
            @Override
            public void onRinging(SipAudioCall call, SipProfile caller) {
                super.onRinging(call, caller);
            }

            @Override
            public void onError(SipAudioCall call, int errorCode, String errorMessage) {
                super.onError(call, errorCode, errorMessage);
            }

            @Override
            public void onCallEnded(SipAudioCall call) {
                super.onCallEnded(call);
            }

            @Override
            public void onCallEstablished(SipAudioCall call) {
                super.onCallEstablished(call);
            }
        };
        incomingCall = sessionManager.mSipManager.takeAudioCall(intent, listener);

        userName = incomingCall.getPeerProfile().getDisplayName();
        if (userName == null) {
            userName = incomingCall.getPeerProfile().getUserName();
        }

        showIncomingCall(intent, context);
        sessionManager.mCall = incomingCall;
        System.out.println(incomingCall);

        // sip..updateStatus(incomingCall);

    } catch (Exception e) {

        if (incomingCall != null) {
            incomingCall.close();
        }
        Log.e("IncomingWakeful service", "" + e);
    }
}

/**
 * Handling incoming call and passing it to the IncomingCalActivity
 * 
 * @param intent
 * @param context
 */

private void showIncomingCall(Intent intent, Context context) {

    Intent intentCall = new Intent(context, IncomingCallActivity.class);
    intentCall.putExtra("INCALL_USER_NAME", userName);
    context.startActivity(intentCall);

}

public void answerIncomingCall() {

    try {
        incomingCall.answerCall(30);
        incomingCall.startAudio();
        if (incomingCall.isMuted()) {
            incomingCall.toggleMute();

        }

    }

    catch (Exception e) {
        System.out.println(e.toString());
    }

}

public void rejectIncomingCall() {

    try {
        if (incomingCall != null) {

            incomingCall.endCall();
            incomingCall.close();

        }

    } catch (Exception e) {

        System.out.println(e.toString());
    }

}

}

明确的文件和许可

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
>
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CONFIGURE_SIP" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
    android:name="android.hardware.sip.voip"
    android:required="true" />
<uses-feature
    android:name="android.software.sip"
    android:required="true" />
<uses-feature
    android:name="android.software.voip.sip"
    android:required="true" />
<uses-feature
    android:name="android.hardware.telephony"
    android:required="false" />
<uses-feature
    android:name="android.hardware.wifi"
    android:required="true" />
<uses-feature
    android:name="android.hardware.microphone"
    android:required="true" />

0 个答案:

没有答案