繁体   English   中英

将通知列表中的默认样式更改为BigTextStyle

[英]Changing default style in notification list to BigTextStyle

我有一个方法,该方法通过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类中,还是有一个更好的地方来放置它?

是的,通知的创建和显示通常在广播接收器中完成,或者在广播接收器启动的意向服务中完成。 仅当用户点击通知时,相关活动才会启动。 您可以在此处查看Google的客户端代码示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM