我正在尝试关闭来自前台服务的通知,但尚未找到任何解决方案。我没有使用notificationManager.notify(...)但是startForeground(...)。
我的NotificationCompat.Builder
Intent actionCancelNotification = new Intent(MusicPlayerApp.getAppContext(), NotificationReceiver.class);
actionCancelNotification.setAction(ACTION_DISMISS_NOTIFICATION);
actionCancelNotification.putExtra(PLAYBACK_NOTIFICATION_ID, PLAYBACK_NOTI_ID);
PendingIntent dismissNotiPendingIntent = PendingIntent.getBroadcast(MusicPlayerApp.getAppContext(), 0, actionCancelNotification, 0);
//NotificationCompat.Builder
builder.setCustomBigContentView(getRemoteView())
.setContentTitle("SongPlayback Notification")
.setSmallIcon(R.drawable.ic_playback_notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(MusicPlayerApp.getAppContext().getResources(), R.drawable.ic_playback_notification_icon))
.setContentText("this is content text")
.setSubText("sub text")
.setDeleteIntent(dismissNotiPendingIntent)
.build();
Run Code Online (Sandbox Code Playgroud)
即使我setOnGoing(false); 它仍然没有工作。我遵循了这个线程解决方案:一旦服务不再处于前台,就可以取消来自前台服务的通知
这是新的NotificationCompat.Builder作为官方文档编写的:
//NotificationCompat.Builder
builder.setCustomBigContentView(getRemoteView())
.setContentTitle("SongPlayback Notification")
.setSmallIcon(R.drawable.ic_playback_notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(MusicPlayerApp.getAppContext().getResources(), R.drawable.ic_playback_notification_icon))
.setContentText("this is content text")
.setSubText("sub text")
//this did not work too
.setDeleteIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(MusicPlayerApp.getAppContext(), PlaybackStateCompat.ACTION_STOP)) //this d
.build();
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何解决方案可以解决我的问题。谢谢
我的布局如下
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior=".AppBarFlingBehavior">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax"
android:background="#ff99"/>
</android.support.design.widget.CollapsingToolbarLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_sample"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我向下滑动时AppBarLayout,内容正在向下滚动,突然,我向上滑动时RecyclerView,整个布局有点滞后,然后按照RecyclerView (向上)的滑动方向向上滚动,如您在该视频中看到的。我已经从许多来源尝试了很多解决方案(自定义行为),但到目前为止还没有工作。有什么办法可以解决我的问题吗,我已经被这个问题困扰了一个星期了。非常感谢您花时间解决我的问题。欣赏它。