安卓:如何通过编程知道通知面板是否已经打开?

3

我想知道是否有办法知道通知栏是否已打开。我有以下代码可以从程序中打开通知栏:

Object sbservice = getSystemService( "statusbar" );
Class<?> statusbarManager = Class.forName( "android.app.StatusBarManager" );
Method showsb;
if (Build.VERSION.SDK_INT >= 17) {
    showsb = statusbarManager.getMethod("expandNotificationsPanel");
}
else {
    showsb = statusbarManager.getMethod("expand");
}
showsb.invoke( sbservice );

有没有办法知道面板是否已经打开?


请查看以下链接以获取可行的解决方案:https://stackoverflow.com/questions/53509108/how-to-detect-when-the-notification-system-bar-is-opened/53509109#53509109 - The Hungry Androider
1个回答

4
将以下内容添加到您的Activity中:
@Override public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    // if hasFocus is false, notification panel is open.
}

此函数的文档在此处


它部分正确。系统对话框,如关机和重启对话框,也会使您的窗口失去焦点。 - Run

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接