如何通过Intent打开或展开状态栏?

发布于 2024-11-29 03:49:59 字数 168 浏览 1 评论 0原文

我正在制作一个家庭应用程序,我认为如果我使用全屏并且不显示状态栏,它将是合适的。所以现在我希望能够使用菜单上的按钮打开或展开状态栏,类似于某些默认家庭应用程序在菜单中的方式。我知道这是可能的,因为默认主页就是这样做的。这是出于意图吗?如果可以的话我可以有它的代码吗?如果不好,那么如果你们告诉我如何做,我将不胜感激。谢谢!

I am making a home application and I think that it will be suitable if I use a fullscreen and not show the status bar. So now I want to be able to open or expand the status bar with a button on the menu, similar to the way some default home applications have in the menu. I know its possible since the default home does it. Is this done through an intent? If so can I have the code for it. If not well then I would appreciate it if you guys showed me how. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小忆控 2024-12-06 03:49:59

看看这是否有帮助并让我知道......

 try{

   Object service  = getSystemService("statusbar");
  Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
  Method expand = statusbarManager.getMethod("expand");
  expand.invoke(service);

}
catch(Exception ex){
 ....
}

uses permission : "android.permission.EXPAND_STATUS_BAR";

See if this helps and let me know...

 try{

   Object service  = getSystemService("statusbar");
  Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
  Method expand = statusbarManager.getMethod("expand");
  expand.invoke(service);

}
catch(Exception ex){
 ....
}

uses permission : "android.permission.EXPAND_STATUS_BAR";
独夜无伴 2024-12-06 03:49:59

下面的代码对我有用:

boolean shown = true; 
private void showHide() {
    Window w = this.getWindow();
if(shown)
{
    w.setFlags(0, 
             WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else
{
    w.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
             WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
shown=!shown;
}

The code below works for me:

boolean shown = true; 
private void showHide() {
    Window w = this.getWindow();
if(shown)
{
    w.setFlags(0, 
             WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else
{
    w.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
             WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
shown=!shown;
}
疑心病 2024-12-06 03:49:59

这个对我有用:

清单:

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>

代码:

//    https://gist.github.com/XinyueZ/7bad2c02be425b350b7f requires permission: "android.permission.EXPAND_STATUS_BAR"
@SuppressLint("WrongConstant", "PrivateApi")
@JvmStatic
fun setExpandNotificationDrawer(context: Context, expand: Boolean) {
    try {
        val statusBarService = context.getSystemService("statusbar")
        val methodName =
                if (expand)
                    if (Build.VERSION.SDK_INT >= 17) "expandNotificationsPanel" else "expand"
                else
                    if (Build.VERSION.SDK_INT >= 17) "collapsePanels" else "collapse"
        val statusBarManager: Class<*> = Class.forName("android.app.StatusBarManager")
        val method: Method = statusBarManager.getMethod(methodName)
        method.invoke(statusBarService)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

但是,有人写它不适用于所有设备和 Android 版本(此处),所以我写了一个请求为此添加官方 API,此处

This one worked for me:

manifest:

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>

Code:

//    https://gist.github.com/XinyueZ/7bad2c02be425b350b7f requires permission: "android.permission.EXPAND_STATUS_BAR"
@SuppressLint("WrongConstant", "PrivateApi")
@JvmStatic
fun setExpandNotificationDrawer(context: Context, expand: Boolean) {
    try {
        val statusBarService = context.getSystemService("statusbar")
        val methodName =
                if (expand)
                    if (Build.VERSION.SDK_INT >= 17) "expandNotificationsPanel" else "expand"
                else
                    if (Build.VERSION.SDK_INT >= 17) "collapsePanels" else "collapse"
        val statusBarManager: Class<*> = Class.forName("android.app.StatusBarManager")
        val method: Method = statusBarManager.getMethod(methodName)
        method.invoke(statusBarService)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

However, someone wrote it doesn't work on all devices and Android versions (here), so I wrote a request to add official API for this, here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文