Question

I am working on application having notification system that supports the OS version from 2.3.3 and above. In android OS less than 3 we have the option to set the content intent. The whole notification area is single click-able.

But for the OS 3.0 and above by using Remote-view we have 3 different button to preform respective actions. By opening the notification drawer we can click on any button to perform action.

After the button click by default the notification drawer is not going up(or Hide). Is there any way to hide the notification drawer programmatic-ally. Please help me on this.

Was it helpful?

Solution 2

I fixed that issue with following snippet. But this is not recommended to use. This can be achieved with the help of reflection. In future this may be deprecated.

void collapseStatusBar(Context context) { // Get access to system status bar. This is not public so may be // deprecated in the future Object service = context.getSystemService("statusbar");

Class<?> statusbarManager = null;

try {
    statusbarManager = Class.forName("android.app.StatusBarManager");
} catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.getMessage();
}

// Till 4.1 (JB), StatusBarManager collapse method did the job but from
// 4.2 it's been
// changed to collpasePanels, so perform the job accordingly
if (Build.VERSION.SDK_INT <= 16) {
    Method collapseMethod = null;

    try {
        collapseMethod = statusbarManager.getMethod("collapse");
    } catch (NoSuchMethodException e) {
        e.getMessage();
    }

    collapseMethod.setAccessible(true);

    try {
        collapseMethod.invoke(service);
    } catch (IllegalArgumentException e) {
        e.getMessage();
    } catch (IllegalAccessException e) {
        e.getMessage();
    } catch (InvocationTargetException e) {
        e.getMessage();
    }
} else {
    Method collapsePanelsMethod = null;

    try {
        collapsePanelsMethod = statusbarManager
                .getMethod("collapsePanels");
    } catch (NoSuchMethodException e1) {
        e1.getMessage();
    }

    collapsePanelsMethod.setAccessible(true);

    try {
        collapsePanelsMethod.invoke(service);
    } catch (IllegalArgumentException e) {
        e.getMessage();
    } catch (IllegalAccessException e) {
        e.getMessage();
    } catch (InvocationTargetException e) {
        e.getMessage();
    }
}

}

OTHER TIPS

Are you using something like

NotificationManager mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNM.cancelAll();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top