2017-04-19 15 views
0

ベルリン/東京とキンベイを使用して、長いメッセージテキストを含むGCMプッシュ通知を受信すると、1行だけが表示され、残りのテキストは切り捨てられます。複数行のGCMプッシュ通知をDelphiで表示するにはどうすればよいですか?

インターネットを掘り起こすと、それらの通知が全長で表示されるため、BigContentViewを設定する必要があるようですが、Delphiは公開していないようです。

誰もこれを処理する方法を知っているので、通知は全長で表示されますか?

答えて

0

あなたは1つの2の選択肢があります:

はあなたが必要とする機能を追加するためにユニットSystem.Android.Notification.pas/System.Notification.pasをハックします。それは簡単です、ただ一つの機能を更新する必要があり、この1:

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

関連する問題