如何通过附加按钮从自定义丰富通知中关闭Android> = 3.0中的通知下拉菜单?

mdi*_*ner 5 notifications android android-3.0-honeycomb android-4.0-ice-cream-sandwich

I successfully created a custom rich notification for Android >= 3.0 that shows some text and an additional button. If you click the notification anywhere but on the button in the notification drop-down, the notification is dismissed, the drop-down closed and the specified Intent is launched as expected. If the dedicated button in the notification is clicked, a different Intent is successfully launched, but the drop-down keeps open (and the notification is still there, but I cancel it later, that is not the problem). The Intent launches an Activity which appears behind the notifications drop-down.

我想要实现的是保持所描述的所有当前行为,但也关闭按钮启动的Intent通知下拉 - 这可能吗?或者,如果来自按钮Intent的Activity获得窗口​​焦点就足够了.

这里是自定义通知的代码,如果有帮助:

            Notification.Builder builder = new Notification.Builder(main)
                .setSmallIcon(R.drawable.notification)
                .setAutoCancel(true)
                .setTicker(text)
                .setContentIntent(...);

            RemoteViews layout = new RemoteViews(
                    main.getPackageName(), R.layout.notification);
            layout.setTextViewText(R.id.title, title);
            layout.setTextViewText(R.id.text, text);
            Intent i = new Intent(
                    "snooze", null, main, Snooze.class
            );
            i.putExtra(KEY_WIDGET_ID, widgetId);
            layout.setOnClickPendingIntent(R.id.notification_zzz, PendingIntent.getActivity( main, 0, i, PendingIntent.FLAG_UPDATE_CURRENT ));
            builder.setContent(layout);

            ...
            NotificationManager nm = 
                (NotificationManager)main.getSystemService(Context.NOTIFICATION_SERVICE);
            nm.notify(0, builder.getNotification());
Run Code Online (Sandbox Code Playgroud)

mdi*_*ner 2

在Android开发者办公时间提问: http://www.youtube.com/watch?v =XvLBvdml_Fs(问题从49:10开始)

答案是,这是不可能的,我什至不应该这样做,我对此表示怀疑。这就是我创建功能请求的原因: http://code.google.com/p/android/issues/detail ?id=24762

编辑 08-10-12:从 Android 4.1 开始,这是可能的,因为通知现在可以包含其他操作。有关更多信息,请参阅以下页面: https://developer.android.com/about/versions/android-4.1.html#UI