簡體   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