推送通知单击将打开最新文章,而不是相关文章

时间:2019-04-03 13:34:33

标签: android push-notification

我正在开发一个应用程序,其中我使用自定义推送通知,只要服务器有更新需要发送通知,我就使用通知生成器发送通知,并且一切都按预期运行,并且我正在重定向通过映射通知的标题将用户转到ViewPager上的相关帖子。

我正在附上我正在使用的代码

通知生成器代码

%%timeit
for index, row in df.iterrows():
    unique_before_date = df[df['date'] <= row['date']].groupby(['car_id'])['destination'].nunique()
    df['unique_destinations'][index] = int(unique_before_date[row['car_id']])

839 ms ± 17.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

我正在发送两个带有PendingIntent的变量,即 pushNotificationClick 标题,并在我的Activity中这样接收它。

Intent resultIntentArticle = new Intent(context, HomeActivity.class);
resultIntentArticle.putExtra("pushNotificationClick", "yes");
resultIntentArticle.putExtra("heading", allArticles.get(0).getArticleHeading().trim());
resultIntentArticle.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent resultPendingIntent = PendingIntent.getActivity(context,
        0, resultIntentArticle,
        PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder = new NotificationCompat.Builder(context);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    mBuilder.setSmallIcon(R.mipmap.icon_not);
} else {
    mBuilder.setSmallIcon(R.mipmap.icon_not);
}
mBuilder.setColor(getResources().getColor(R.color.colorPrimary));
mBuilder.setContentTitle("" + allArticles.get(0).getArticleHeading().trim())
        .setContentText("" + allArticles.get(0).getArticleContent().trim())
        .setAutoCancel(true)
        .setContentIntent(resultPendingIntent);
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
    int importance = NotificationManager.IMPORTANCE_HIGH;
    NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
    notificationChannel.enableLights(true);
    assert mNotificationManager != null;
    mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
    mNotificationManager.createNotificationChannel(notificationChannel);
}
assert mNotificationManager != null;
mNotificationManager.notify((int) System.currentTimeMillis() /* Request Code */, mBuilder.build());
currentNotificationStatus = "sent";
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("currentNotificationStatus" +
        "", "" + currentNotificationStatus).apply();

现在的问题是,每当我们收到2-3条通知,并且用户单击我收到的第一个通知时,我仍然会在活动中获得最新的Notification标题。以前它的工作完全正常,但现在我没有任何头绪。

0 个答案:

没有答案