【问题标题】:Notification is Lost when when I minimized it当我最小化它时通知丢失
【发布时间】:2016-05-10 06:55:52
【问题描述】:

我有一个问题,当我在设备中收到通知时,我打开它,当我最小化通知时,它会从最小化应用的列表中消失,因此我无法再看到我的通知。

这是消息处理服务的代码

 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    private void setNotification(String message,String bundledata)
    {
        NotificationManager  mNotificationManager = (NotificationManager)
                this.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(this, GcmNotificationRedirect.class);
        notificationIntent.putExtra("pushMessage", message);
        notificationIntent.putExtra("bundleData",bundledata);
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );

        PendingIntent resultPendingIntent =
                PendingIntent.getActivity(this, NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);


       // NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setContentTitle(title)
                        .setPriority(Notification.PRIORITY_MAX)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(message))
                        .setContentText(message)
                        .setNumber(pushNumber);

            mBuilder.setColor(this.getResources().getColor(R.color.theme_color));
            mBuilder.setSmallIcon(R.drawable.app_icon);
            mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), getNotificationIcon()));

        mBuilder.setContentIntent(resultPendingIntent);
        mBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
        Notification notification = mBuilder.build();
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        mNotificationManager.notify(NOTIFICATION_ID, notification);

    }

这是将数据传递给适当活动的活动..

//GcmNotificationRedirect
  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pushRedirect();

    }

    private void pushRedirect()
    {
        pushMessage = getIntent().getStringExtra("pushMessage");
        bundleData = getIntent().getStringExtra("bundleData");
        parsePushNotifiactionJson(pushMessage,bundleData);
        finish();
    }

    private void parsePushNotifiactionJson(String pushMessage, String bundleJSONData){
        Intent pushNotiInetent = null;

        if(pushMessage!=null && bundleJSONData!=null) {
            try {

                JSONObject jsonObject = new JSONObject(bundleJSONData);

                if (jsonObject.getString("type").equals(PRODUCT_PAGE)) {

                    pojo = new Push_Notification_Pojo(jsonObject.getString("productId"), jsonObject.getString("type"),pushMessage);
                    pushNotiInetent = new Intent(this, ProductDetail.class);
                    pushNotiInetent.putExtra("push_notification_pojo", pojo);
                    startActivity(pushNotiInetent);
                }

                else
                {
                    pojo = new Push_Notification_Pojo(jsonObject.getString("promotionId"), jsonObject.getString("type"), pushMessage, true);

                    if(pojo!=null)
                    {
                        pushNotiInetent = new Intent(this,PushNotificationPromotion.class);
                        pushNotiInetent.putExtra("pushMessage", pushMessage);
                        pushNotiInetent.putExtra("bundleData",bundleData);
                        startActivity(pushNotiInetent);
                    }
                }
                Log.d("Push",pojo.getType()+" "+pojo.getProductId()+" "+pojo.getPromotionId() );

            }

            catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }


}

一切正常,但是当我最小化它时我无法恢复通知..

【问题讨论】:

    标签: android push-notification minimize


    【解决方案1】:

    您可能是指当您关闭通知时。这是预期的行为。如果您想保留通知,即始终可见,您可以使用 setOngoing(true)

     NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setContentTitle(title)
                        .setPriority(Notification.PRIORITY_MAX)
                        .setStyle(new NotificationCompat.BigTextStyle()
                        .bigText(message))
                        .setOngoing(true)
                        .setContentText(message)
                        .setNumber(pushNumber);
    

    要关闭它,请使用

     NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    
        notificationManager.cancel(NOTIFICATION_ID);
    

    问候, 弗拉基米尔

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多