2015-10-13 36 views
4

正在開發一個VoIP應用程序。有一個後臺服務顯示來電通知,當電話未鎖定且應用程序處於後臺狀態時,它會按預期工作(顯示來電呼叫對話框)。Android WhatsApp喜歡來電通知

我怎樣才能生成一個對話框與交互式按鈕,如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); 

而這裏是在按鈕按下時解鎖設備的代碼。雖然這看起來像是爲手機解鎖,但屏幕仍在打開,但手機仍處於鎖定狀態。主頁按鈕不起作用。

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

你有解決辦法嗎? –

回答

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