我有一个方法,它通过 Parse API 从推送通知接收文本,并将其打包到通知对象中。很标准的东西。我的问题是我正在尝试使用 BigTextStyle 在列表中显示我的通知,但它拒绝这样做,并且只显示一行文本并且两指手势不会导致它扩展。
但是,如果我点击打开应用程序的通知,然后返回到通知列表,它将以 BigTextStyle 显示并响应手势。所以,我的猜测是,以某种方式点击通知正在激活它并允许 BigTextStyle 代码启动。
我喜欢点击通知打开应用程序,但我不想强迫我的用户打开应用程序然后再次关闭它以查看我的消息的全文。那么有没有一种方法可以让通知从一开始就以 BigTextStyle 格式显示,或者让第一次单击“激活”通知,允许看到完整的消息文本,然后第二次单击打开应用程序?任何帮助,将不胜感激。
这是我在 Notification 方法中的代码:
public void receiveNotification() {
NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle();
bts.bigText(SplashActivity.globalDataString);
bts.setSummaryText("Tap to open app, swipe to dismiss message");
NotificationCompat.Builder m = new NotificationCompat.Builder(this);
m.setContentTitle("New Push Notification")
.setContentText(SplashActivity.globalDataString)
.setSmallIcon(R.drawable.app_icon)
.setStyle(bts)
.build();
Intent openApp = new Intent(this, MenuActivity.class);
// This ensures that navigating backward from the Activity leads out of
// the application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MenuActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(openApp);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
m.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(pushMessageID, m.build());
pushMessageID++;
//reset notification
flag1 = false;
}
编辑:我认为我的问题在于我从哪里调用我的 receiveNotification() 方法。现在我在我的应用程序启动活动的 onCreate() 方法中拥有它,回顾过去没有多大意义。我应该把它放在我的 broadcastReceiver 类中,还是有更好的地方放它?