简体   繁体   English

Android whatsapp就像通话通知一样

[英]Android whatsapp like call notification

Am developing a voip application. 我正在开发一个voip应用程序。 There is a background service which shows incoming call notifications, which works as expected (showing an incoming call dialog) when the phone is not locked and app is in background state. 有一个后台服务显示来电通知,当手机未锁定且应用处于后台状态时,该通知按预期工作(显示来电对话框)。

How can i generate a dialog with interactive buttons, like whatsapp incoming call notification; 如何生成带有交互式按钮的对话框,如whatsapp来电通知; even when the phone is locked? 即使手机被锁定了?

Any heads up on this one or documentation that i can look up? 我可以抬头看看这个或文件吗?

I can send an inapp notification for an incoming call, but that seems to be not enough for the purpose. 我可以为来电发送一个inapp通知,但这似乎不足以达到目的。 I would need a full blow dialog interface which has a button or similar that would in turn open the application. 我需要一个完整的打击对话框界面,它有一个按钮或类似的按钮,然后打开应用程序。

I am using Quickblox as the voip service provider. 我使用Quickblox作为voip服务提供商。

Thanks in advance 提前致谢

I have tried unlocking the phone, on a button press 我已经尝试按下按钮解锁手机

Here is my code to open a dialog from the background service. 这是我从后台服务打开对话框的代码。

viewToShowOnLockedScreen = View.inflate(getApplicationContext(), R.layout.activity_background_call, null);
        viewToShowOnLockedScreen.setTag(TAG);

        int top = getApplicationContext().getResources().getDisplayMetrics().heightPixels / 2;

        final WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, Utils.dpToPx(300), 0, 0,
                WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON ,
                PixelFormat.RGBA_8888);
viewToShowOnLockedScreen.setVisibility(View.VISIBLE);
        Animation mAnimation = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.abc_slide_in_top);
        viewToShowOnLockedScreen.startAnimation(mAnimation);
        mWindowManager.addView(viewToShowOnLockedScreen, mLayoutParams);
        mWindowManager.updateViewLayout(viewToShowOnLockedScreen, mLayoutParams);

And here is the code to unlock the device on a button press. 这是在按下按钮时解锁设备的代码。 Though this looks like it unlocks the phone, the screen is on, but the phone is still locked. 虽然这看起来像解锁手机,但屏幕已开启,但手机仍处于锁定状态。 Home button does'nt work. 主页按钮不起作用。

KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
        final KeyguardManager.KeyguardLock kl = km .newKeyguardLock("MyKeyguardLock");
        kl.disableKeyguard();

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
    wakeLock.acquire();

Not really an answer, a work around i should say. 不是一个答案,我应该说一个解决方法。

I coul'dnt unlock the screen. 我无法解锁屏幕。 However I have updated the application to listen to Intent.ACTION_USER_PRESENT and added necessary to logic in the app to answer calls once the user has unlocked the device at the point of incoming call. 但是,我已经更新了应用程序以侦听Intent.ACTION_USER_PRESENT,并在应用程序中添加必要的逻辑,以便在用户在来电时解锁设备时应答呼叫。 Here is the code. 这是代码。

mUnlockStatusFilter = new IntentFilter();
        mUnlockStatusFilter.addAction(Intent.ACTION_USER_PRESENT);
    mUnlockStateIntentReceiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent i) {
                    if (i.getAction().equals(Intent.ACTION_USER_PRESENT)) {
                       //Do something phone is unlocked
                        Log.d(TAG,"Screen unlocked");
                        if(isWaitingForUnlock){
                            stopCallNotification();
                            if(Foreground.get().isForeground()){
                                Log.d(TAG, "App is in foreground; Sending a broadcast");
                                Intent intent = new Intent();
                                intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
                                intent.setAction(BaseActivityWithSignalling.onReceiveNewSession);
                                intent.putExtra("code", BaseActivityWithSignalling.onReceiveNewSessionCode);
                                sendBroadcast(intent);
                                Log.d(TAG, "Send broadcast for onReceiveNewSession");
                            }else{
                                Log.d(TAG, "App is in background; Showing activity");
                                Intent showCallingFromBG = new Intent(LMService.this, BackgroundCall.class);
                                showCallingFromBG.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(showCallingFromBG);
                            }
                        }
                    }
                }
            };
    registerReceiver(mUnlockStateIntentReceiver, mUnlockStatusFilter);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM