0
使用柏林/東京和Kinvey,當收到包含長消息文本的GCM推送通知時,只顯示一行,其餘文本被剪切。如何在Delphi中顯示多行GCM推送通知?
挖掘互聯網,似乎要讓這些通知以全長顯示,需要設置BigContentView,但Delphi不公開它。
有沒有人知道如何處理這個問題,所以通知會全部顯示?
使用柏林/東京和Kinvey,當收到包含長消息文本的GCM推送通知時,只顯示一行,其餘文本被剪切。如何在Delphi中顯示多行GCM推送通知?
挖掘互聯網,似乎要讓這些通知以全長顯示,需要設置BigContentView,但Delphi不公開它。
有沒有人知道如何處理這個問題,所以通知會全部顯示?
你有一個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和建立自己從頭
謝謝你的提示!黑客似乎並不那麼簡單,因爲沒有定義BigTextStyle。這是我的第一個移動應用程序,所以我需要弄清楚我將如何實現它。 – WarmBooter