Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

android - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...