Android whatsapp就像通话通知一样

Vee*_*eru 5 android android-service android-notifications

我正在开发一个voip应用程序.有一个后台服务显示来电通知,当手机未锁定且应用处于后台状态时,该通知按预期工作(显示来电对话框).

如何生成带有交互式按钮的对话框,如whatsapp来电通知; 即使手机被锁定了?

我可以抬头看看这个或文件吗?

我可以为来电发送一个inapp通知,但这似乎不足以达到目的.我需要一个完整的打击对话框界面,它有一个按钮或类似的按钮,然后打开应用程序.

我使用Quickblox作为voip服务提供商.

提前致谢

我已经尝试按下按钮解锁手机

这是我从后台服务打开对话框的代码.

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);
Run Code Online (Sandbox Code Playgroud)

这是在按下按钮时解锁设备的代码.虽然这看起来像解锁手机,但屏幕已开启,但手机仍处于锁定状态.主页按钮不起作用.

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();
Run Code Online (Sandbox Code Playgroud)

Vee*_*eru 2

我应该说,这并不是一个真正的答案,而是一个解决方法。

我无法解锁屏幕。不过,我已经更新了应用程序以侦听 Intent.ACTION_USER_PRESENT,并在应用程序中添加了必要的逻辑,以便在用户在来电时解锁设备后接听电话。这是代码。

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);
Run Code Online (Sandbox Code Playgroud)