How to disable closing the notification panel after clicking on your own notification

How can I disable closing the notification panel after the user clicks on my notification (on the body, not on the action buttons)?

I use notificationBuilder.setOngoing(true)and notificationBuilder.setAutoCancel( false), but the panel continues to close. What am I doing wrong?

Add: I also use this code:

  Intent intentNotification intentNotification = new Intent( contextApplication, MyBroadcast.class);
  intentNotification.putExtra( "reload", "1");
  PendingIntent pendingIntent = PendingIntent.getBroadcast( contextApplication, 0, intentNotification, PendingIntent.FLAG_UPDATE_CURRENT);
  notificationBuilder.setContentIntent( pendingIntent);

  notificationBuilder.setAutoCancel( false); // this not work because setContentIntent work

If I remove this notification panel with a code, it is displayed on the screen. When I add this hidden code bar. But I need to create a call in MyBroadcast by clicking on the notification body. Any way to invoke my broadcast by clicking on the notification body?

Add2: In response to @NIPHIN, I am trying to restore the inheritance panel inside my translator:

if( android.os.Build.VERSION.SDK_INT <= 16)  Class.forName( "android.app.StatusBarManager").getMethod( "expand").invoke( contextApplication.getSystemService( "statusbar"));
 else  Class.forName( "android.app.StatusBarManager").getMethod( "expandNotificationsPanel").invoke( contextApplication.getSystemService( "statusbar"));
// manifest need <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>

, : .

?

+4
4

, . AOSP , , ClickHandler,

BaseStatusBar.java

       try {
            mBarService.onNotificationClick(mPkg, mTag, mId);
        } catch (RemoteException ex) {
        }

        // close the shade if it was open
        animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
+3

: -

setAutoCancel(false)

+2

notificationBuilder.setAutoCancel(false)

,

private int currentApiVersion = android.os.Build.VERSION.SDK_INT;
Object sbservice = context.getSystemService("statusbar");

try {
    Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
    if (currentApiVersion <= 16) {
        Method collapse = statusbarManager.getMethod("collapse");
        collapse.invoke(sbservice);
    } else {
        Method collapse2 = statusbarManager.getMethod("collapsePanels");
        collapse2.invoke(sbservice);
    }
} catch (Exception e) {
    e.printStackTrace();
}

+2
    nm.cancel(uniqueID);

nm - NotoficationManager

-1

All Articles