4

I use this code to expand status bar:

Object sbservice = getSystemService( "statusbar" );
Class<?> statusbarManager = Class.forName( "android.app.StatusBarManager" );
Method showsb;
if (Build.VERSION.SDK_INT >= 17) {
    showsb = statusbarManager.getMethod("expandNotificationsPanel");
} 
else { 
    showsb = statusbarManager.getMethod("expand");
} 
showsb.invoke( sbservice );

With permission:

 <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

It work well exept with the samsung lollipop device nothing happen. Does anyone know how to expand status bar on samsung lollipop device? Thanks!

Hai nguyen thanh
  • 718
  • 7
  • 17

1 Answers1

2

Finally I found it but I need to use the Accessibility service:

public class MyAccessibilityService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    Log.e("MyAccessibilityService", "get event");
    if (event.getEventType() == AccessibilityEvent.TYPE_TOUCH_INTERACTION_END) {
        switch (event.getAction()) {
            case 1:
                Log.e("MyAccessibilityService ", "home");
                performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
                break;
            case 2:
                Log.e("MyAccessibilityService ", "back");
                performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
                break;
            case 3:
                Log.e("MyAccessibilityService ", "power");
                performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);
                break;
            case 4:
                Log.e("MyAccessibilityService ", "noti");
                performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
                break;

        }


    }
}

Fire even:

AccessibilityEvent event1 = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END);
        event1.setClassName(className);
        event1.getText().add("noti");
        event1.setAction(4);
        event1.setPackageName(packageName);
        event1.setEnabled(true);
        AccessibilityManager manager = (AccessibilityManager)context.getSystemService(Context.ACCESSIBILITY_SERVICE);
        AccessibilityRecordCompat recordCompat = AccessibilityEventCompat.asRecord(event1);
        recordCompat.setSource(v);
        if (Utility.isAccessibilityEnable(context)) {
            manager.sendAccessibilityEvent(event1);
        }
Hai nguyen thanh
  • 718
  • 7
  • 17