2017-07-10 175 views
1

我正在爲android用戶開發一種聯繫人提供程序。主要功能是當有人撥打電話(鎖定或未鎖定)時,它會顯示一個彈出窗口,其中包含有關誰在打電話的信息。問題在於,當Android的版本低於7.0時,它會正確運行,但是在Android 7.0和更高版本中,當手機被鎖定並且有人呼叫POPUPWINDOW在呼叫屏幕布局下方並且僅在我掛斷時纔會看到。因此,如果有人可以幫助如何使彈出窗口出現在Android 7.0的通話屏幕布局上方,我將非常感激。如何在Android 7.0版本中顯示通話屏幕上方的彈出窗口

pd。請記住,在7.0以下版本中運行,因此問題出現在新版本中。 截圖上的版本如何運行低於7.0 enter image description here

public class IncomingCallActivity extends Activity { 
int mCurrentX = 0; 
int mCurrentY = 500; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    final LinearLayout fondo; 
    TextView text; 
    try { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.layout_empty); 

     getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | 
       WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | 
       WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | 
       WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | 
       WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | 
       WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 

     LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE); 

     final View popupView = layoutInflater.inflate(R.layout.layout_incoming_call, null); 

     Button button = (Button)popupView.findViewById(R.id.close_window); 
     text = (TextView) popupView.findViewById(R.id.text); 

     button.setText("CLOSE WINDOW"); 

     final PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, 300); 
     new Handler().postDelayed(new Runnable() { 
      public void run() { 
       popupWindow.showAtLocation(popupView, Gravity.NO_GRAVITY,mCurrentX,mCurrentY); 
       popupView.bringToFront(); 
      } 
     }, 100); 

     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       popupWindow.dismiss(); 
       finish(); 
      } 
     }); 

     popupView.setOnTouchListener(new View.OnTouchListener() { 
      int orgX, orgY; 
      int offsetX, offsetY; 

      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       switch (event.getAction()) { 
        case MotionEvent.ACTION_DOWN: 
         orgX = (int) (mCurrentX - event.getRawX()); 
         orgY = (int) (mCurrentY - event.getRawY()); 
         break; 
        case MotionEvent.ACTION_MOVE: 
         mCurrentX = (int) event.getRawX() + orgX; 
         mCurrentY = (int) event.getRawY() + orgY; 
         popupWindow.update(mCurrentX, mCurrentY, -1, -1, true); 
         break; 
       } 
       return true; 
      } 
     }); 

     String number = getIntent().getStringExtra(
       TelephonyManager.EXTRA_INCOMING_NUMBER); 
     text.setText("Incoming call from " + number); 

    } catch (Exception e) { 
     Log.d("Exception", e.toString()); 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

}

+0

您好,我也遇到這個問題,你解決了嗎? – aleksandrbel

+0

沒有在最新版本... –

+0

檢查我的答案,我剛剛找到解決方案 – aleksandrbel

回答

0

我已經找到了API的解決方案> 23. 我相信你也可以手動啓動它,如果你在清單中有android.permission.SYSTEM_ALERT_WINDOW文件轉至設置>應用程序>您的應用程序>高級 - 在其他應用(如果你向下滾動)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) { 

    //If the draw over permission is not available open the settings screen 
    //to grant the permission. 
    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, 
    Uri.parse("package:" + getPackageName())); 
    startActivityForResult(intent, PERMISSION_DRAW_OVER_OTHER_APP); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == PERMISSION_DRAW_OVER_OTHER_APP) { 
     //Check if the permission is granted or not. 
     if (resultCode == RESULT_OK) { 
      // write your view here ... 
     } else { //Permission is not available 
      Toast.makeText(this, 
        "Draw over other app permission not available", 
        Toast.LENGTH_SHORT).show(); 
     } 
    } else { 
     super.onActivityResult(requestCode, resultCode, data); 
    } 
} 
相關問題