android-keeplive icon indicating copy to clipboard operation
android-keeplive copied to clipboard

1像素的透明的问题

Open 904079904 opened this issue 7 years ago • 2 comments

导致 1像素 透明页面浮在 上面 不能点击后面的页面

904079904 avatar Apr 20 '18 03:04 904079904

have you declared this activity in your AndroidManifest.xml? 如果 配置了 再次亮屏幕就是黑色的

904079904 avatar Apr 20 '18 04:04 904079904

have you declared this activity in your AndroidManifest.xml? 如果 配置了 再次亮屏幕就是黑色的

我调试过,KeepLiveManager.getInstance().setKeepLiveActivity(this); 这句是执行了,但是get到的PixelActivity是null,我改成用广播的方式了,暂未发现问题

Log.i(TAG, "发送finish广播,结束流氓Activity"); getApplicationContext().sendBroadcast(new Intent("finish_Activity"));

public class PixelActivity extends AppCompatActivity { private final static String TAG = PixelActivity.class.getSimpleName(); private BroadcastReceiver endReceiver;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    Logger.d(TAG, "PixelActivity -> onCreate");

    Window window = getWindow();
    window.setGravity(Gravity.LEFT | Gravity.TOP);
    WindowManager.LayoutParams params = window.getAttributes();
    params.x = 0;
    params.y = 0;
    params.height = 1;
    params.width = 1;
    window.setAttributes(params);

    //结束该页面的广播
    endReceiver = new BroadcastReceiver()
    {
        @Override
        public void onReceive(Context context, Intent intent)
        {
            Logger.d(TAG, "接受到finish的广播");
            finish();
        }
    };
    registerReceiver(endReceiver, new IntentFilter("finish_Activity"));
    //检查屏幕状态
    checkScreen();
}

@Override
protected void onResume()
{
    super.onResume();
    Logger.d(TAG, "PixelActivity -> onResume");
    checkScreen();
}

@Override
protected void onRestart()
{
    super.onRestart();
    Logger.d(TAG, "PixelActivity -> onRestart");
}

@Override
protected void onDestroy()
{
    super.onDestroy();
    Logger.d(TAG, "PixelActivity -> onDestroy");
    if (endReceiver != null)
        unregisterReceiver(endReceiver);

}

/**
 * 检查屏幕状态  isScreenOn为true  屏幕“亮”结束该Activity
 */
private void checkScreen()
{
    PowerManager pm = (PowerManager) PixelActivity.this.getSystemService(Context.POWER_SERVICE);
    if (pm != null)
    {
        boolean isScreenOn = pm.isScreenOn();
        Logger.d(TAG, "PixelActivity isScreenOn->" + isScreenOn);
        if (isScreenOn)
        {
            finish();
        }
    }

}

}

gaoyuyu avatar Nov 07 '18 02:11 gaoyuyu