我正在为Android用户开发一种联系提供程序。主要功能是当有人呼叫电话(锁定或非锁定)时,它会显示一个弹出窗口,其中包含有关谁正在呼叫的信息。问题是,如果android的版本低于7.0,它可以正常运行,但在Android 7.0及以上版本中,当手机被锁定时,有人称之为POPUPWINDOW出现在呼叫屏幕布局之下,只有在我挂机时才能看到。因此,如果有人可以帮助如何让弹出窗口出现在Android 7.0的调用屏幕布局上面,我将非常感激。
概率pd。请记住,在低于7.0的版本中运行所以问题出在新版本中。 关于它如何在7.0以下版本中运行的屏幕截图
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 :(得分: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);
}
}