Android 拨打电话后,键入_KEYGUARD保持全屏模式

Android 拨打电话后,键入_KEYGUARD保持全屏模式,android,window,overriding,statusbar,Android,Window,Overriding,Statusbar,我们将向客户提供设备,他们需要能够通过按钮呼叫我们。在我的全屏活动中有一个按钮可以调用帮助台电话号码,因此onClick()它执行以下操作: try { Intent intent = new Intent(Intent.ACTION_CALL); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); intent.setData(Uri.parse("tel:" + phoneNumber

我们将向客户提供设备,他们需要能够通过按钮呼叫我们。在我的全屏
活动中
有一个按钮可以调用帮助台电话号码,因此
onClick()
它执行以下操作:

    try {
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.setData(Uri.parse("tel:" + phoneNumber));
        mContext.startActivity(intent);
    } catch (Exception e) {
        Toast.makeText(mContext, mContext.getString(R.string.couldntcall), Toast.LENGTH_LONG).show();
    }
当拨号器关闭时,标题栏突然保持可见,我猜这与覆盖
HOME
按钮有关:

@Override
public void onAttachedToWindow()
{  //HOMEBUTTON
    if(OnLockMode())
    {   
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
          super.onAttachedToWindow();
    }
    else
    {
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION); 
        super.onAttachedToWindow();
    }
}
有人能解决这个问题吗

我尝试了以下方法:

    try {
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.setData(Uri.parse("tel:" + phoneNumber));
        mContext.startActivity(intent);
    } catch (Exception e) {
        Toast.makeText(mContext, mContext.getString(R.string.couldntcall), Toast.LENGTH_LONG).show();
    }
我在舱单上写了:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
并用于
OnCreate

requestWindowFeature(Window.FEATURE_NO_TITLE);
onCreate()
onResume()
中:

标题栏仍然显示。

将其添加到清单中

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
其中home_视图是xml文件的父视图

 @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
            return false;
        }

 public void onWindowFocusChanged(boolean hasFocus)
     {
             try
             {
                if(!hasFocus)
                {
                     Object service  = getSystemService("statusbar");
                     Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
                     Method collapse = statusbarManager.getMethod("collapse");
                     collapse .setAccessible(true);
                     collapse .invoke(service);
                }
             }
             catch(Exception ex)
             {
             }
     }
@覆盖
公共布尔onKeyDown(int-keyCode,KeyEvent事件){
返回false;
}
WindowFocusChanged上的公共无效(布尔hasFocus)
{
尝试
{
如果(!hasFocus)
{
对象服务=getSystemService(“状态栏”);
Class statusbarManager=Class.forName(“android.app.statusbarManager”);
方法collapse=statusbarManager.getMethod(“collapse”);
collapse.setAccessible(true);
调用(服务);
}
}
捕获(例外情况除外)
{
}
}
您无法捕获主事件,您唯一能做的就是将应用程序设置为主类别,并让用户选择

 <category android:name="android.intent.category.HOME" />

要求用户选择要启动的应用程序很糟糕。
 <category android:name="android.intent.category.HOME" />