通知按钮不起作用

时间:2018-04-07 18:26:01

标签: android notifications android-notifications

我正在我的应用程序中创建custoom通知。通知显示,但是当我点击按钮时,按钮不起作用。我不知道该怎么做。我查看了stackoverflow上的所有答案,但没有得到这个想法。所以,请帮帮我。

这是通知代码

private void customNotification() {

    Intent closeButton = new Intent("Download_Cancelled");
    closeButton.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(getContext(), 0, closeButton, 0);

    RemoteViews notificationView = new RemoteViews(getContext().getPackageName(), R.layout.notification);

    NotificationManager notificationManager = (NotificationManager)getContext().getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext())
            .setSmallIcon(R.drawable.music)
            .setContent(notificationView)
            .setChannelId(ID);
    notificationView.setOnClickPendingIntent(R.id.next, pendingSwitchIntent);

    notificationManager.notify(0, builder.build());

}

这是广播活动

public class NotificationBroadcast extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Toast.makeText(context,"thanks",Toast.LENGTH_LONG).show();

    }
}

这是显而易见的

<receiver android:name=".BlankFragment2$NotificationBroadcast">
    <intent-filter>
        <action android:name="Download_Cancelled" />
    </intent-filter>
</receiver>

0 个答案:

没有答案