【问题标题】:Android whatsapp like call notificationAndroid whatsapp 喜欢来电通知
【发布时间】:2016-01-10 20:39:03
【问题描述】:

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

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

任何关于这个或我可以查找的文档的提示?

我可以为来电发送应用内通知,但这似乎还不够。我需要一个完整的对话框界面,它有一个按钮或类似的按钮,可以依次打开应用程序。

我使用 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);

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

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();

【问题讨论】:

  • 你有解决办法吗?

标签: android android-service android-notifications


【解决方案1】:

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

我无法解锁屏幕。但是,我已经更新了应用程序以收听 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);

【讨论】:

    猜你喜欢
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-17
    • 2022-06-21
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多