【发布时间】:2014-09-25 06:24:31
【问题描述】:
如何在用户单击我的通知(在正文上,而不是操作按钮上)后禁用关闭通知面板?
我使用notificationBuilder.setOngoing(true) 和notificationBuilder.setAutoCancel( false),但面板继续关闭。我做错了什么?
补充:我也用这个代码:
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
如果我删除此代码通知面板,则屏幕上会继续显示。当我添加此代码面板时隐藏。但是我需要通过单击通知正文来创建对 MyBroadcast 的调用。有什么方法可以通过点击通知正文来调用我的广播?
Add2:在@NIPHIN 的回答中,我尝试在我的广播接收器中恢复导航面板:
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"/>
这项工作正确,但不清楚:面板首先关闭并在片刻(秒)后恢复。
有什么方法可以禁用关闭面板?
【问题讨论】:
-
你能找到解决这个问题的方法吗?
-
不,不关闭栏我找不到解决方案:(
-
我发现您可以为此使用 RemoteViews。战斧播放器是开源的,并且能够做到这一点。看看他们的 PlaybackService.java 文件,看看他们是如何做到的。 github.com/tomahawk-player/tomahawk-android.gitgithub.com/tomahawk-player/tomahawk-android/blob/master/src/org/…
标签: java android notifications