【发布时间】: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