2017-04-19 101 views
0

使用柏林/东京和Kinvey,当收到包含长消息文本的GCM推送通知时,只显示一行,其余文本被剪切。如何在Delphi中显示多行GCM推送通知?

挖掘互联网,似乎要让这些通知以全长显示,需要设置BigContentView,但Delphi不公开它。

有没有人知道如何处理这个问题,所以通知会全部显示?

回答

0

你有一个2选择:

哈克单位System.Android.Notification.pas/System.Notification.pas添加你需要的功能。这很容易,只是一个功能需要更新,这一个:

function TNotificationCenterAndroid.CreateNativeNotification(const ANotification: TNotification): JNotification; 

    function GetDefaultNotificationSound: Jnet_Uri; 
    begin 
    Result := TJRingtoneManager.JavaClass.getDefaultUri(TJRingtoneManager.JavaClass.TYPE_NOTIFICATION); 
    end; 

    function GetDefaultIconID: Integer; 
    begin 
    Result := TAndroidHelper.Context.getApplicationInfo.icon; 
    end; 

    function GetDefaultIcon: JBitmap; 
    begin 
    Result := TJBitmapFactory.JavaClass.decodeResource(TAndroidHelper.Context.getResources(), GetDefaultIconID); 
    end; 

    function GetContentTitle: JCharSequence; 
    begin 
    if ANotification.Title.IsEmpty then 
     Result := StrToJCharSequence(TAndroidHelper.ApplicationTitle) 
    else 
     Result := StrToJCharSequence(ANotification.Title); 
    end; 

    function GetContentText: JCharSequence; 
    begin 
    Result := StrToJCharSequence(ANotification.AlertBody); 
    end; 

    function GetContentIntent: JPendingIntent; 
    var 
    Intent: JIntent; 
    begin 
    Intent := TAndroidHelper.Context.getPackageManager().getLaunchIntentForPackage(TAndroidHelper.Context.getPackageName()); 
    Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_SINGLE_TOP or TJIntent.JavaClass.FLAG_ACTIVITY_CLEAR_TOP); 
    SaveNotificationIntoIntent(Intent, ANotification); 
    Result := TJPendingIntent.JavaClass.getActivity(TAndroidHelper.Context, TGeneratorUniqueID.GenerateID, Intent, TJPendingIntent.JavaClass.FLAG_UPDATE_CURRENT); 
    end; 

var 
    NotificationBuilder: JNotificationCompat_Builder; 
begin 
    NotificationBuilder := TJNotificationCompat_Builder.JavaClass.init(TAndroidHelper.Context); 
    NotificationBuilder := NotificationBuilder.setDefaults(TJNotification.JavaClass.DEFAULT_LIGHTS); 
    if ANotification.SmallIconId <> 0 then NotificationBuilder := NotificationBuilder.setSmallIcon(ANotification.SmallIconId) 
    else NotificationBuilder := NotificationBuilder.setSmallIcon(GetDefaultIconID); 
    if ANotification.largeIconObj <> nil then NotificationBuilder := NotificationBuilder.setLargeIcon(ANotification.largeIconObj); 
    NotificationBuilder := NotificationBuilder.setContentTitle(GetContentTitle); 
    NotificationBuilder := NotificationBuilder.setContentText(GetContentText); 
    NotificationBuilder := NotificationBuilder.setTicker(GetContentText); 
    NotificationBuilder := NotificationBuilder.setContentIntent(GetContentIntent); 
    NotificationBuilder := NotificationBuilder.setNumber(ANotification.Number); 
    NotificationBuilder := NotificationBuilder.setAutoCancel(True); 
    NotificationBuilder := NotificationBuilder.setWhen(TJDate.Create.getTime); 
    if (ANotification.Color <> TalphaColorRec.null) and 
    (TJBuild_VERSION.JavaClass.SDK_INT >= 21) then NotificationBuilder := NotificationBuilder.setColor(ANotification.Color); 
    if ANotification.VibratePattern <> nil then NotificationBuilder := NotificationBuilder.setVibrate(ANotification.VibratePattern); 

    if ANotification.EnableSound then 
    if ANotification.SoundName.IsEmpty then 
     NotificationBuilder := NotificationBuilder.setSound(GetDefaultNotificationSound) 
    else 
     NotificationBuilder := NotificationBuilder.setSound(StrToJURI(ANotification.SoundName)); 

    // Action buttons won't appear on platforms prior to Android 4.1!!! 
    // http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#addAction 
    Result := NotificationBuilder.Build; 
end; 

或第二变型,避免使用德尔福TnotificationCenter和建立自己从头

+0

谢谢你的提示!黑客似乎并不那么简单,因为没有定义BigTextStyle。这是我的第一个移动应用程序,所以我需要弄清楚我将如何实现它。 – WarmBooter