elc*_*lie 6 delphi android push-notification firemonkey
我在Android设备上的推送通知中的小图标有问题。图标显示黑色。
我已按照本文中pudnivec74指示的步骤操作,如何使用DELPHI在Android设备上的通知中更改小图标图像,它可以工作,但仅在应用程序运行时,当应用程序关闭时,图标静止图像仍显示为黑色。
我还在文件AndroidManifest.template.xml中添加了以下几行:
<meta-data android: name = "com.google.firebase.messaging.default_notification_icon" android: resource = "@ drawable / ic_notification" />
并保持不变。
有人知道解决方案吗?
这是我使用的代码:
procedure TFrmMain.FormCreate(Sender: TObject);
begin
try
{$IF DEFINED(ANDROID)}
APushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.GCM);
APushService.AppProps[TPushService.TAppPropNames.GCMAppID] :=UResource.NUMEROPROYECTOANDROID;
{$ELSE}
APushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.APS);
{$ENDIF}
AServiceConnection := TPushServiceConnection.Create(APushService);
AServiceConnection.Active := True;
{$IF DEFINED(ANDROID)}
AServiceConnection.OnReceiveNotification := OnReceiveNotificationPushAndroid;
{$ELSE}
AServiceConnection.OnReceiveNotification := OnReceiveNotificationPushiOS;
{$ENDIF}
VKAutoShowMode := TVKAutoShowMode.Always;
except on E: Exception do
end;
end;
procedure TFrmMain.OnReceiveNotificationPushAndroid(Sender: TObject;
const ANotification: TPushServiceNotification);
var
{$IFDEF ANDROID}
Ntf: JNotification;
ntfBuilder: JNotificationCompat_Builder;
ntfManager: JNotificationManager;
{$ENDIF}
Mensaje, Titulo: String;
begin
{$IFDEF ANDROID}
try
//ShowMessage(ANotification.Json.ToString);
Titulo := Copy(ANotification.Json.GetValue('title').ToString, 2, Length(ANotification.Json.GetValue('title').ToString)-2);
Mensaje := Copy(ANotification.Json.GetValue('message').ToString, 2, Length(ANotification.Json.GetValue('message').ToString)-2);
ntfBuilder:= TJNotificationCompat_Builder.JavaClass.init(TAndroidHelper.Context);
ntfBuilder.setSmallIcon(TAndroidHelper.Context.getResources.getIdentifier(StringToJString('ic_notification'), StringToJString('drawable'), TAndroidHelper.Context.getPackageName));
ntfBuilder.setContentTitle(StrToJCharSequence(Titulo));
ntfBuilder.setContentText(StrToJCharSequence(Mensaje));
ntfBuilder.setAutoCancel(True);
Ntf:= ntfBuilder.build;
Ntf.defaults := TJNotification.JavaClass.DEFAULT_SOUND;
if Ntf.defaults <> TJNotification.JavaClass.DEFAULT_VIBRATE then
Ntf.defaults := Ntf.defaults + TJNotification.JavaClass.DEFAULT_VIBRATE;
ntfManager:= TJNotificationManager.Wrap((TAndroidHelper.Context.getSystemService(TJContext.JavaClass.NOTIFICATION_SERVICE) as ILocalObject).GetObjectID);
ntfManager.notify(1, Ntf);
except on E: Exception do
end;
{$ENDIF}
end;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
205 次 |
| 最近记录: |