For example, I need to push the status bar (statusbar). For this there is an expand method in the StatusBarManager class. How can I call him? I understand something like this:

In the root of the project, create the android folder, in it the app folder and in it create the StatusBarManager class with the expand body method.

 package android.app.StatusBarManager; public class StatusBarManager { public void expand() {} } 

Then in activity

 StatusBarManager sbm = (StatusBarManager) getSystemService("statusbar"); sbm.expand(); 

Will it be possible to achieve a status bar? In theory, the class will be compiled and executed exactly as a class from the framework. If this doesn't work, then how is the normal compiled code that comes in the SDK executed? What is there? Why is the code being executed from the framework and not from the SDK?

  • In the StatusBarManager from which package? - post_zeew
  • android.app , but my project. What will happen if compiled? Now there is no possibility, very interesting. After all, the same package is in the framework and in my package - Flippy

1 answer 1

For this there is an expand method in the StatusBarManager class. How can I call him?

With reflection, for example .

The option you suggested will fall at runtime with ClassCastException .

You define the StatusBarManager class, then you use this class in the activation class (explicitly indicating that this class should be imported from your package).

The getSystemService("statusbar") method returns an object of the StatusBarManager class, and this is not the class that you defined, but the system one.

Next, you try to explicitly convert the StatusBarManager class StatusBarManager (system) to the StatusBarManager class you created. Since this conversion is not possible, a ClassCastException exception will be ClassCastException .

  • Now everything is clear. How, then, is implemented in the DropDownStatusBar application? I decompiled it, and the system class import and method call is directly specified there. One activity. How did they specify it, is it not included in the SDK? - Flippy
  • @ SergeyGrushin; It’s hard to say without seeing the whole code. - post_zeew