Android whatsapp as call notification

Develops a voip application. There is a help desk that displays notifications of incoming calls that work as expected (showing an incoming call dialog) when the phone is not locked and the application is in the background.

How can I generate a dialog with interactive buttons, for example, notification of an incoming whatsapp call; even when the phone is locked?

Any heads-up on this or the documentation I can find?

I can send an inapp notification for an incoming call, but this is not enough for this purpose. I need a full dialog with delete dialog, which has a button or similar, which, in turn, will open the application.

I use Quickblox as a VoIP provider.

Thank you in advance

I tried to unlock the phone by pressing the button

Here is my code to open a dialog from a 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 when the button is pressed. Although it looks like it is unlocking the phone, the screen is on, but the phone is still locked. The Home button does not 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();
+4
source share
1 answer

Actually not the answer, work around has to say.

I can not unlock the screen. However, I updated the application to listen to Intent.ACTION_USER_PRESENT and add it to the application logic to answer calls as soon as the user unlocked the device at the point of the incoming call. 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);
+1
source

Source: https://habr.com/ru/post/1611389/


All Articles