我希望对话和来电屏幕都是可点击的。我尝试了该站点的不同解决方案,但有些在某些条件下有效,而另一些则无效。我想创建一个像真正的呼叫者这样的应用程序,我已经从BroadcastReceiver
. 当屏幕未锁定时,我的代码可以完美运行,因为传入的屏幕不是全屏的。但是当屏幕全屏时,对话活动在调用屏幕上出现几毫秒,然后在调用屏幕后面。
这是我从 BroadcastReceiver 调用的活动代码
public class IncomingCallActivity extends AppCompatActivity {
private static final int MSG_ID_CHECK_TOP_ACTIVITY = 1;
private String userName;
private String TAG = IncomingCallActivity.class.getSimpleName();
private Window wind;
private PowerManager powerManager;
private PowerManager.WakeLock wakeLock;
/*private ActivityManager mActivityManager;
private boolean mDismissed = false;*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
wind = this.getWindow();
wind.requestFeature(Window.FEATURE_NO_TITLE);
wind.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
wind.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
wind.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
wind.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Lock");
wakeLock.acquire();
setContentView(R.layout.activity_incoming_call);
userName = getIntent().getStringExtra(IncomingCallReceiver.NAME_KEY);
final TextView textView = (TextView) findViewById(R.id.tvUsername);
textView.setText(userName);
final ImageView ivCancel = (ImageView) findViewById(R.id.ivCancel);
ivCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wakeLock.release();
IncomingCallActivity.this.finish();
}
});
}
}