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).
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).
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"/>
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