锁定来电屏幕上的对话框 [英] dialog over lock incoming call screen

查看:116
本文介绍了锁定来电屏幕上的对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望对话框和来电屏幕都可以单击。我尝试了与本网站不同的解决方案,但有些情况在某些情况下可行,而另一些则没有。我想创建一个像真正的调用者一样的应用程序,我从 BroadcastReceiver 调用了一个活动。当屏幕未锁定(因为传入屏幕不是全屏)时,我的代码可以完美工作。但是当屏幕全屏显示时,对话框活动将在调用屏幕上显示几毫秒,然后在调用屏幕后面。

I want that both dialog and incoming call screen be clickable. I have tried different solutions from this site, but some works in some condtions and others don't. I want to create an app like true caller, I have called an activity from BroadcastReceiver. My code works perfectly when the screen is not locked because the incoming screen is not full screen. But when the screen is full screen the dialog activity appears for few milliseconds over the calling screen and then goes behind the calling screen.

这是我的活动代码,从BroadcastReceiver调用

Here is my code of my activity which I called from 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();
        }
    });

}

}

推荐答案

     //Add Permissions in Manifest file and don't forget to check overlay permission
            <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
            <uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW"/>

     //Create Class Level Variable  or as per requirement 

                WindowManager.LayoutParams mWindowsParams;
                WindowManager mWindowManager;
                View mDialogView;

    //initialize variable
 mWindowsParams =new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
                                    WindowManager.LayoutParams.WRAP_CONTENT,
                                    WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                                    PixelFormat.TRANSLUCENT);
mWindowManager=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);

//Add Window on your event
 mWindowManager.addView(mDialogView, mWindowsParams);

//For Remove window

 if (mDialogView.getParent() != null) {
      try {
          mWindowManager.removeViewImmediate(mDialogView);
            } catch (Exception e) {

             }
        }

这篇关于锁定来电屏幕上的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆