android - 使用 Delphi XE 10.3 Rio 在 Android 上更改推送通知中的小图标
问题描述
我对 Android 设备上的推送通知中的小图标有疑问。图标显示为黑色。
我已经按照 pudnivec74 在这篇文章How to change small icon image in notice on Android device with DELPHI 中指示的步骤进行操作,并且它可以工作,但只有在应用程序运行时,当应用程序关闭时,图标仍然显示为黑色。
我还在文件 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;
解决方案
推荐阅读
- hadoop - 如何以最快的方式将数据形式的 csv 文件插入 OpenTSDB?
- python - 在 PyQt 应用程序中遇到异常时出现意外的 SIGABRT 和错误代码
- python - 如果在另一个数据框中找到其列值,则从数据框中删除一行
- azure - 有没有办法结合本地 DNS + Azure 提供的名称解析?
- bash - sed 命令在文件中添加额外的字符
- flowtype - 如何在不嵌入文字的情况下创建 Flow Union 运行时细化
- django - django管理页面登录导致IIS崩溃,每次都需要重启iis
- c++ - _tfopen 出现错误 22 的可能原因是什么?
- java - Json反序列化错误Spring Boot测试 - 无法构造实例
- python-3.x - 如何安装上下文?