[Android] How to turn the Notification panel on and off using StatusBarManager

Using the private (formalized from API level 29?) API called StatusBarManager in the Android app, the Notification panel (push notification list) I will explain how to turn on / off the display of the guy).

StatusBarManager source code

The source code for StatusBarManager can be found here (https://android.googlesource.com/platform/frameworks/base/+/android-4.3_r2.1/core/java/android/app/StatusBarManager.java).

Required permissions

You need to add the following to AndroidManifest.xml. It's not runtime permission, so just add it to AndroidManifest.xml.

AndroidManifest.xml


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

Source code

It's a private class, so put a try / catch in it so that anything can happen. To open the panel, call android.app.StatusBarManager.expandNotificationsPanel.

Sample to open the panel


if(ContextCompat.checkSelfPermission(this, Manifest.permission.EXPAND_STATUS_BAR) != PackageManager.PERMISSION_GRANTED)
    return;

try {
    Object service = getSystemService("statusbar");
    Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
    Method expand = statusBarManager.getMethod("expandNotificationsPanel");
    expand.invoke(service);
}
catch (Exception e){
    e.printStackTrace();
}

On the contrary, when closing the panel, the quick setting screen will be closed at the same time, but android.app.StatusBarManager.collapsePanels will be called.

Sample to close the panel


if(ContextCompat.checkSelfPermission(this, Manifest.permission.EXPAND_STATUS_BAR) != PackageManager.PERMISSION_GRANTED)
    return;

try {
    Object service = getSystemService("statusbar");
    Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
    Method expand = statusBarManager.getMethod("collapsePanels");
    expand.invoke(service);
}
catch (Exception e){
    e.printStackTrace();
}

Recommended Posts

[Android] How to turn the Notification panel on and off using StatusBarManager
How to turn off ChromeDriver notification bar (Java)
How to use OpenCV 4 on Android and view camera live view
How to install JDK 8 on Windows without using the installer
How to run React and Rails on the same server
How to "hollow" View on Android
How to install and configure the monitoring tool "Graphite" on Ubuntu
How to place and share SwiftLint config files on the server
Try using the service on Android Oreo
How to detect microphone conflicts on Android
How to change the timezone on Ubuntu
How to find the tens and ones
How to place geckodriver (Selenium WebDriver) on the path using Maven command
How to solve the problem that notification cannot be requested on iOS14
[Android] How to pass images and receive callbacks when sharing using ShareCompat
[Ruby On Rails] How to search the contents of params using include?
How to narrow down the image format from the gallery on Android and then select and import multiple images
[Ruby on Rails] How to log in with only your name and password using the gem devise
How to output Excel and PDF using Excella
How to execute and mock methods using JUnit
How to play audio and music using javascript
How to implement the breadcrumb function using gretel
If you are using Android Room and want to change the column definition
[Ruby] How to calculate the total amount using the initialize method and class variables
How to find the distance and angle between two points on a plane
How to find the total score and average score
[Java] Memo on how to write the source
How to share on the host side (windows) and guest side (CentOS 7) with VirtualBox
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
How to fix the problem that the upper half is cut off when using UITabBar
[Swift5] How to round off, round down, and round up to the second or third decimal place
[Ruby on Rails] How to change the column name
[Android] Display images and characters on the ViewPager tab
[Android Studio] [Java] How to fix the screen vertically
Run the Android emulator on Docker using Android Emulator Container Scripts
How to hover and click on Selenium DOM elements
[Android] How to get the setting language of the terminal
How to convert A to a and a to A using AND and OR in Java
Install MySQL 5.6 on CentOS6 [How to specify the version]
[Ruby] How to get the tens place and the ones place
(Ruby on Rails6) How to create models and tables
I want to simplify the log output on Android
[Ruby On Rails] How to search and save the data of the parent table from the child table
[Ruby On Rails] How to update the calculated result to an integer type column using update_column
How to take a screenshot with the Android Studio emulator
How to test including images when using ActiveStorage and Faker
How to easily implement in-app purchase using itemstore <Implementation: Android>
Difference between Java and JavaScript (how to find the average)
Android app to select and display images from the gallery
How to Install Elixir and Phoenix Framework on Ubuntu 20.04 LTS
How to set and describe environment variables using Rails zsh
How to disable Set-Cookie from API on the front side
[2020 version] How to send an email using Android Studio Javamail
How to make an app using Tensorflow with Android Studio
How to join a table without using DBFlute and sql
How to switch Java in the OpenJDK era on Mac
How to check the extension and size of uploaded files
How to get started with JDBC using PostgresSQL on MacOS
How to play MIDI files using the Java Sound API
Zip and upload multiple files to Firebase Storage on Android.
How to check the database of apps deployed on Heroku