Android - notification line height from service

The application I'm working on is a service that runs in the background in android. The problem is that I need to determine the height of the notification bar for some features of the service.

I found a number of solutions for this, for regular actions - the view inside the action can determine its own height without a notification bar, based on checking its actual size of the view from the onSizeChanged event after it is already drawn. However, this does not apply to a service that does not have a physical appearance.

I would really appreciate any ideas on getting the size of the notification bar at the system level, maybe?

Many thanks!

Vitaliy

+3
source share
3 answers

, . , , .

+1

, .

, Android (Sense UI, MotoBlur ..)

- :

Drawable phoneCallIcon = getResources().getDrawable(android.R.drawable.stat_sys_phone_call);

int height = phoneCallIcon.getIntrinsicHeight();

Nexus One 38 , .


"" .

:

int notificationBarResources[] = {
            android.R.drawable.stat_sys_phone_call,
            android.R.drawable.stat_notify_call_mute,
            android.R.drawable.stat_notify_sdcard,
            android.R.drawable.stat_notify_sync,
            android.R.drawable.stat_notify_missed_call,
            android.R.drawable.stat_sys_headset,
            android.R.drawable.stat_sys_warning };
int notificationBarHeight = -1;
    for (int i = 0; i < notificationBarResources.length; i++) {
        try {
            Drawable phoneCallIcon = getResources().getDrawable(
                    android.R.drawable.stat_sys_phone_call);
            if ((notificationBarHeight = phoneCallIcon.getIntrinsicHeight()) != -1) {
                break;
            }
        } catch (Resources.NotFoundException e) {
            // Nothing to do
        }
    }
+1

. . , , onMesure, :

   protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    widthView = MeasureSpec.getSize(widthMeasureSpec);
    heightView = MeasureSpec.getSize(heightMeasureSpec);
   }

However, I cannot lay out the images inside this method (image animation will continue to call this method).

To find out the actual height of the view, I will need to do:

screenHeight - statusBarHeight

so I could use this value in the view constructor.

I cannot believe that it should be so complex as to provide a solution to such a simple requirement.

0
source

Source: https://habr.com/ru/post/1750093/


All Articles