Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I find a reference to the StatusBarManager class directly?

To dynamically drag down notification area in Android, the only solution is this

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

This works wonderfully, but why the nastiness with reflection? Why can't I find a reference to the StatusBarManager class directly? Why is there not a constant in the Context class for the "statusbar" service?

like image 447
Ashwin Singh Avatar asked Jul 04 '12 06:07

Ashwin Singh


1 Answers

why the nastiness with reflection?

Because it is not part of the Android SDK. Only people interested in creating unreliable apps would try to interact with the StatusBarManager outside of the Android source code itself, since the core Android team and device manufacturers are welcome to change anything outside of the SDK whenever they wish.

Why can't I find a reference to the StatusBarManager class directly?

Because it is not part of the Android SDK. There are a great many classes and methods in Android framework classes that are marked with the @hide annotation, for all sorts of reasons: unwillingness to commit to support the API indefinitely, "security by obscurity", etc.

Why is there not a constant in the Context class for the "statusbar" service?

Because it is not part of the Android SDK. You are certainly welcome to supply patches to the AOSP to have StatusBarManager be "promoted" to the same status as the other system services (e.g., LocationManager, NotificationManager). If the StatusBarManager situation is merely an oversight after the SDK was created in ~2007, your patches might well be accepted and you would see the change in an upcoming version of Android.

like image 163
CommonsWare Avatar answered Oct 01 '22 09:10

CommonsWare