处置应用程序后的通知服务

时间:2018-06-26 09:13:44

标签: android android-service android-notifications

场景1:我启动了应用程序,它显示了通知(比如说3条通知)。 单击所有通知后,似乎可以在不完全破坏应用程序的情况下按每个通知使用预期的意图(通过单击最近的应用程序菜单,然后向左或向右滑动将其关闭)。

方案2:我完全销毁了该应用程序并重新启动该应用程序,它显示了相同的通知(3条通知)。 单击第一个通知后,似乎还可以,而第二个和最后一个通知都没有响应预期的意图

这是我的服务通知代码

for(int i = 0; i<jArray.length(); i++){
                        JSONObject json_data = jArray.getJSONObject(i);

                        inv_interview_schedule_id[i] = json_data.getString("inv_interview_schedule_id");
                        inv_company_name[i] = json_data.getString("inv_company_name");
                        inv_job_title[i] = json_data.getString("inv_job_title");
                        inv_add_instruction[i] = json_data.getString("inv_add_instruction");
                        inv_schedule[i] = json_data.getString("inv_schedule");

                        Intent notificationIntent = new Intent(InvitationNotification.this, InvitationDetails.class);
                        notificationIntent.putExtra("interview_schedule_id", json_data.getString("inv_interview_schedule_id"));

                        notificationIntent.setAction("Default");

                        Intent acceptIntent = new Intent(InvitationNotification.this, InvitationDetails.class);
                        acceptIntent.putExtra("interview_schedule_id", json_data.getString("inv_interview_schedule_id"));

                        acceptIntent.setAction("Accept");

                        Intent rejectIntent = new Intent(InvitationNotification.this, InvitationDetails.class);
                        rejectIntent.putExtra("interview_schedule_id", json_data.getString("inv_interview_schedule_id"));

                        Bitmap calendar_icon_bmp = ((BitmapDrawable) getApplicationContext().getResources()
                                .getDrawable(R.drawable.invitation_notif)).getBitmap();

                        NotificationCompat.Builder builder = new NotificationCompat.Builder(InvitationNotification.this)
                                .setSmallIcon(R.mipmap.esii_logo)
                                .setLargeIcon(calendar_icon_bmp)
                                .setContentTitle(json_data.getString("inv_job_title"))
                                .setContentText(json_data.getString("inv_schedule"))
                                .addAction(R.drawable.accept_icon_notif, "Accept", PendingIntent.getActivity(InvitationNotification.this, Integer.parseInt(json_data.getString("inv_interview_schedule_id")), acceptIntent, PendingIntent.FLAG_UPDATE_CURRENT))
                                .addAction(R.drawable.reject_icon_notif, "Reject", PendingIntent.getActivity(InvitationNotification.this, Integer.parseInt(json_data.getString("inv_interview_schedule_id")), rejectIntent, PendingIntent.FLAG_UPDATE_CURRENT))
                                .setDefaults(Notification.DEFAULT_ALL)
                                .setAutoCancel(true);

                        builder.setContentIntent(PendingIntent.getActivity(InvitationNotification.this, Integer.parseInt(json_data.getString("inv_interview_schedule_id")), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT));

                        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                        assert manager != null;
                        manager.notify(Integer.valueOf(json_data.getString("inv_interview_schedule_id")), builder.build());

                    }

0 个答案:

没有答案