feat: 安卓端本地自定义铃声方案完成
This commit is contained in:
parent
b45507fabb
commit
f33c5c76eb
BIN
android/app/src/main/res/raw/ring_wx.mp3
Normal file
BIN
android/app/src/main/res/raw/ring_wx.mp3
Normal file
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 78 KiB |
BIN
images/call_me_icon.png
Normal file
BIN
images/call_me_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
@ -10,6 +10,7 @@ import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
|
|||||||
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
||||||
import 'package:star_lock/login/register/entity/SendValidationCodeEntity.dart';
|
import 'package:star_lock/login/register/entity/SendValidationCodeEntity.dart';
|
||||||
import 'package:star_lock/tools/eventBusEventManage.dart';
|
import 'package:star_lock/tools/eventBusEventManage.dart';
|
||||||
|
import 'package:star_lock/tools/push/notification_service.dart';
|
||||||
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
||||||
import 'package:star_lock/tools/storage.dart';
|
import 'package:star_lock/tools/storage.dart';
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ class StarLockRegisterLogic extends BaseGetXController {
|
|||||||
Storage.saveLoginData(entity.data);
|
Storage.saveLoginData(entity.data);
|
||||||
Storage.setBool(saveIsVip, entity.data!.isVip == 1);
|
Storage.setBool(saveIsVip, entity.data!.isVip == 1);
|
||||||
eventBus.fire(MineInfoChangeRefreshUI());
|
eventBus.fire(MineInfoChangeRefreshUI());
|
||||||
XSJPushProvider().initLocalNotification(isCancelLocalPush: false);
|
NotificationService().init(); // 初始化通知服务
|
||||||
Get.offNamedUntil(Routers.starLockMain, (Route route) => false);
|
Get.offNamedUntil(Routers.starLockMain, (Route route) => false);
|
||||||
BlueManage().scanDevices.clear(); //清除设备缓存
|
BlueManage().scanDevices.clear(); //清除设备缓存
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -96,6 +96,5 @@ Future<void> privacySDKInitialization() async {
|
|||||||
// 初始化JPush服务
|
// 初始化JPush服务
|
||||||
final XSJPushProvider jpushProvider = XSJPushProvider();
|
final XSJPushProvider jpushProvider = XSJPushProvider();
|
||||||
await jpushProvider.initJPushService();
|
await jpushProvider.initJPushService();
|
||||||
await jpushProvider.initLocalNotification(isCancelLocalPush: false);
|
|
||||||
NotificationService().init(); // 初始化通知服务
|
NotificationService().init(); // 初始化通知服务
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import 'package:star_lock/main/lockMian/lockList/lockList_logic.dart';
|
|||||||
import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_entity.dart';
|
import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_entity.dart';
|
||||||
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
|
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
|
||||||
import 'package:star_lock/tools/eventBusEventManage.dart';
|
import 'package:star_lock/tools/eventBusEventManage.dart';
|
||||||
|
import 'package:star_lock/tools/push/notification_service.dart';
|
||||||
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
||||||
import 'package:star_lock/tools/showTipView.dart';
|
import 'package:star_lock/tools/showTipView.dart';
|
||||||
import 'package:star_lock/tools/store_service.dart';
|
import 'package:star_lock/tools/store_service.dart';
|
||||||
@ -92,7 +93,7 @@ class LockMainLogic extends BaseGetXController {
|
|||||||
// 初始化JPush服务并绑定设备ID
|
// 初始化JPush服务并绑定设备ID
|
||||||
final XSJPushProvider jpushProvider = XSJPushProvider();
|
final XSJPushProvider jpushProvider = XSJPushProvider();
|
||||||
await jpushProvider.initJPushService();
|
await jpushProvider.initJPushService();
|
||||||
await jpushProvider.initLocalNotification(isCancelLocalPush: false);
|
NotificationService().init(); // 初始化通知服务
|
||||||
}
|
}
|
||||||
|
|
||||||
//绑定星图
|
//绑定星图
|
||||||
@ -364,7 +365,7 @@ class LockMainLogic extends BaseGetXController {
|
|||||||
// 初始化JPush服务并绑定设备ID
|
// 初始化JPush服务并绑定设备ID
|
||||||
final XSJPushProvider jpushProvider = XSJPushProvider();
|
final XSJPushProvider jpushProvider = XSJPushProvider();
|
||||||
await jpushProvider.initJPushService();
|
await jpushProvider.initJPushService();
|
||||||
await jpushProvider.initLocalNotification(isCancelLocalPush: false);
|
NotificationService().init(); // 初始化通知服务
|
||||||
|
|
||||||
// 开启UDP
|
// 开启UDP
|
||||||
// AppLog.log('onReady() LockMainLogic');
|
// AppLog.log('onReady() LockMainLogic');
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_
|
|||||||
import 'package:star_lock/network/api_repository.dart';
|
import 'package:star_lock/network/api_repository.dart';
|
||||||
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
|
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
|
||||||
import 'package:star_lock/tools/baseGetXController.dart';
|
import 'package:star_lock/tools/baseGetXController.dart';
|
||||||
|
import 'package:star_lock/tools/push/notification_service.dart';
|
||||||
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
||||||
import 'package:star_lock/tools/storage.dart';
|
import 'package:star_lock/tools/storage.dart';
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ class LockMainXHJLogic extends BaseGetXController {
|
|||||||
// 初始化JPush服务并绑定设备ID
|
// 初始化JPush服务并绑定设备ID
|
||||||
final XSJPushProvider jpushProvider = XSJPushProvider();
|
final XSJPushProvider jpushProvider = XSJPushProvider();
|
||||||
await jpushProvider.initJPushService();
|
await jpushProvider.initJPushService();
|
||||||
await jpushProvider.initLocalNotification(isCancelLocalPush: false);
|
NotificationService().init(); // 初始化通知服务
|
||||||
}
|
}
|
||||||
|
|
||||||
//绑定星图
|
//绑定星图
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import 'package:star_lock/mine/mineSet/mineSet/mineSet_state.dart';
|
|||||||
import 'package:star_lock/mine/mineSet/mineSet/userSettingInfoEntity.dart';
|
import 'package:star_lock/mine/mineSet/mineSet/userSettingInfoEntity.dart';
|
||||||
import 'package:star_lock/mine/mineSet/mineSet/weChatQRCodeEntity.dart';
|
import 'package:star_lock/mine/mineSet/mineSet/weChatQRCodeEntity.dart';
|
||||||
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
|
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
|
||||||
|
import 'package:star_lock/tools/push/notification_service.dart';
|
||||||
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
||||||
import 'package:star_lock/tools/showCupertinoAlertView.dart';
|
import 'package:star_lock/tools/showCupertinoAlertView.dart';
|
||||||
import 'package:star_lock/tools/storage.dart';
|
import 'package:star_lock/tools/storage.dart';
|
||||||
@ -141,6 +142,9 @@ class MineSetLogic extends BaseGetXController {
|
|||||||
'logout_result': '成功',
|
'logout_result': '成功',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 取消所有本地通知
|
||||||
|
await NotificationService().cancelAllNotifications();
|
||||||
|
|
||||||
// UdpHelp().closeUDP();
|
// UdpHelp().closeUDP();
|
||||||
logOut();
|
logOut();
|
||||||
|
|
||||||
@ -148,7 +152,6 @@ class MineSetLogic extends BaseGetXController {
|
|||||||
Get.updateLocale(Get.deviceLocale!);
|
Get.updateLocale(Get.deviceLocale!);
|
||||||
|
|
||||||
BlueManage().disconnect();
|
BlueManage().disconnect();
|
||||||
XSJPushProvider().initLocalNotification(isCancelLocalPush: true);
|
|
||||||
StartChartManage().destruction();
|
StartChartManage().destruction();
|
||||||
StartChartManage().closeUdpSocket();
|
StartChartManage().closeUdpSocket();
|
||||||
Get.offNamedUntil(Routers.starLockLoginPage, (Route route) => false);
|
Get.offNamedUntil(Routers.starLockLoginPage, (Route route) => false);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ import 'package:star_lock/talk/starChart/proto/gateway_reset.pb.dart';
|
|||||||
import 'package:star_lock/talk/starChart/proto/generic.pb.dart';
|
import 'package:star_lock/talk/starChart/proto/generic.pb.dart';
|
||||||
import 'package:star_lock/talk/starChart/proto/talk_expect.pb.dart';
|
import 'package:star_lock/talk/starChart/proto/talk_expect.pb.dart';
|
||||||
import 'package:star_lock/talk/starChart/proto/talk_request.pb.dart';
|
import 'package:star_lock/talk/starChart/proto/talk_request.pb.dart';
|
||||||
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
||||||
import 'package:star_lock/tools/storage.dart';
|
import 'package:star_lock/tools/storage.dart';
|
||||||
|
|
||||||
class UdpTalkRequestHandler extends ScpMessageBaseHandle
|
class UdpTalkRequestHandler extends ScpMessageBaseHandle
|
||||||
@ -62,7 +64,10 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
|
|||||||
// 发送预期数据、通知锁板需要获取视频数据
|
// 发送预期数据、通知锁板需要获取视频数据
|
||||||
_handleSendExpect();
|
_handleSendExpect();
|
||||||
// 播放铃声
|
// 播放铃声
|
||||||
playRingtone();
|
//test:使用自定义铃声
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
playRingtone();
|
||||||
|
}
|
||||||
// 显示状态栏弹窗
|
// 显示状态栏弹窗
|
||||||
_showTalkRequestNotification(talkObjectName: talkObjectName);
|
_showTalkRequestNotification(talkObjectName: talkObjectName);
|
||||||
// 设置为等待接听状态
|
// 设置为等待接听状态
|
||||||
@ -78,9 +83,7 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
|
|||||||
// 收到来电请求时进行本地通知
|
// 收到来电请求时进行本地通知
|
||||||
Future<void> _showTalkRequestNotification(
|
Future<void> _showTalkRequestNotification(
|
||||||
{required String talkObjectName}) async {
|
{required String talkObjectName}) async {
|
||||||
/**
|
final Map<String, dynamic> message = {
|
||||||
*
|
|
||||||
final Map<String, dynamic> message = {
|
|
||||||
'platform': 'all',
|
'platform': 'all',
|
||||||
'audience': 'all',
|
'audience': 'all',
|
||||||
'notification': <String, Map<String, Object>>{
|
'notification': <String, Map<String, Object>>{
|
||||||
@ -96,7 +99,7 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
|
|||||||
};
|
};
|
||||||
|
|
||||||
XSJPushProvider().showCustomNotification(message);
|
XSJPushProvider().showCustomNotification(message);
|
||||||
*/
|
/*
|
||||||
const AndroidNotificationDetails androidPlatformChannelSpecifics =
|
const AndroidNotificationDetails androidPlatformChannelSpecifics =
|
||||||
AndroidNotificationDetails('1', 'flutter_channel',
|
AndroidNotificationDetails('1', 'flutter_channel',
|
||||||
importance: Importance.max,
|
importance: Importance.max,
|
||||||
@ -113,6 +116,7 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
|
|||||||
await flutterLocalNotificationsPlugin.show(0, '呼叫提醒'.tr,
|
await flutterLocalNotificationsPlugin.show(0, '呼叫提醒'.tr,
|
||||||
'${'收到来自'.tr}($talkObjectName)${'锁的呼叫'.tr}。', platformChannelSpecifics,
|
'${'收到来自'.tr}($talkObjectName)${'锁的呼叫'.tr}。', platformChannelSpecifics,
|
||||||
payload: 'item x');
|
payload: 'item x');
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:audioplayers/audioplayers.dart';
|
import 'package:audioplayers/audioplayers.dart';
|
||||||
@ -76,7 +77,10 @@ class ScpMessageBaseHandle {
|
|||||||
|
|
||||||
// 播放铃声
|
// 播放铃声
|
||||||
void playRingtone() async {
|
void playRingtone() async {
|
||||||
await audioManager.playRingtone();
|
//test:使用自定义铃声
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
await audioManager.playRingtone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 停止播放铃声
|
// 停止播放铃声
|
||||||
|
|||||||
@ -9,4 +9,6 @@ class MessageConstant {
|
|||||||
static const int keyReceive = 40;
|
static const int keyReceive = 40;
|
||||||
//锁设置变更
|
//锁设置变更
|
||||||
static const int lockSetChange = 50;
|
static const int lockSetChange = 50;
|
||||||
|
//呼叫推送自定义大图模式
|
||||||
|
static const int talkPushBigImage = 70;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import 'package:get/get.dart';
|
|||||||
import 'package:star_lock/app_settings/app_settings.dart';
|
import 'package:star_lock/app_settings/app_settings.dart';
|
||||||
import 'package:star_lock/tools/eventBusEventManage.dart';
|
import 'package:star_lock/tools/eventBusEventManage.dart';
|
||||||
import 'package:star_lock/tools/push/message_constant.dart';
|
import 'package:star_lock/tools/push/message_constant.dart';
|
||||||
|
import 'package:star_lock/tools/push/notification_service.dart';
|
||||||
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
||||||
|
|
||||||
class MessageManagement {
|
class MessageManagement {
|
||||||
//分析消息数据
|
//分析消息数据
|
||||||
@ -105,6 +107,10 @@ class MessageManagement {
|
|||||||
// }
|
// }
|
||||||
eventBus.fire(RefreshLockInfoDataEvent(keyId: keyId, lockId: lockId));
|
eventBus.fire(RefreshLockInfoDataEvent(keyId: keyId, lockId: lockId));
|
||||||
break;
|
break;
|
||||||
|
case MessageConstant.talkPushBigImage:
|
||||||
|
// XSJPushProvider().showCustomNotification(data);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw Exception('无法识别eventNo 参数:$eventNo');
|
throw Exception('无法识别eventNo 参数:$eventNo');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class NotificationService {
|
|||||||
NotificationDetails(android: androidPlatformChannelSpecifics);
|
NotificationDetails(android: androidPlatformChannelSpecifics);
|
||||||
|
|
||||||
await _flutterLocalNotificationsPlugin.show(
|
await _flutterLocalNotificationsPlugin.show(
|
||||||
0,
|
1,
|
||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
platformChannelSpecifics,
|
platformChannelSpecifics,
|
||||||
@ -52,7 +52,7 @@ class NotificationService {
|
|||||||
// //读取网络下载图片
|
// //读取网络下载图片
|
||||||
// final ByteArrayAndroidBitmap? bigPicture = await _downloadImage(imageUrl);
|
// final ByteArrayAndroidBitmap? bigPicture = await _downloadImage(imageUrl);
|
||||||
// 读取本地图片
|
// 读取本地图片
|
||||||
final ByteData imageData = await rootBundle.load('images/call_me_icon.jpg');
|
final ByteData imageData = await rootBundle.load('images/call_me_icon.png');
|
||||||
final Uint8List imageBytes = imageData.buffer.asUint8List();
|
final Uint8List imageBytes = imageData.buffer.asUint8List();
|
||||||
final ByteArrayAndroidBitmap bigPicture =
|
final ByteArrayAndroidBitmap bigPicture =
|
||||||
ByteArrayAndroidBitmap(imageBytes);
|
ByteArrayAndroidBitmap(imageBytes);
|
||||||
@ -76,15 +76,14 @@ class NotificationService {
|
|||||||
importance: Importance.max,
|
importance: Importance.max,
|
||||||
priority: Priority.high,
|
priority: Priority.high,
|
||||||
styleInformation: bigPictureStyleInformation,
|
styleInformation: bigPictureStyleInformation,
|
||||||
sound: const RawResourceAndroidNotificationSound(
|
sound: const RawResourceAndroidNotificationSound('ring_wx'), // 自定义铃声
|
||||||
'assets/ring1.mp3'), // 自定义铃声
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final NotificationDetails platformChannelSpecifics =
|
final NotificationDetails platformChannelSpecifics =
|
||||||
NotificationDetails(android: androidPlatformChannelSpecifics);
|
NotificationDetails(android: androidPlatformChannelSpecifics);
|
||||||
|
|
||||||
await _flutterLocalNotificationsPlugin.show(
|
await _flutterLocalNotificationsPlugin.show(
|
||||||
0,
|
1,
|
||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
platformChannelSpecifics,
|
platformChannelSpecifics,
|
||||||
@ -104,4 +103,9 @@ class NotificationService {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 取消所有本地通知
|
||||||
|
Future<void> cancelAllNotifications() async {
|
||||||
|
await _flutterLocalNotificationsPlugin.cancelAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,9 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
||||||
import 'package:jpush_flutter/jpush_flutter.dart';
|
import 'package:jpush_flutter/jpush_flutter.dart';
|
||||||
import 'package:star_lock/flavors.dart';
|
import 'package:star_lock/flavors.dart';
|
||||||
import 'package:star_lock/mine/minePersonInfo/minePersonInfoEditAccount/minePersonInfoEditAccount/mineUnbindPhoneOrEmail_entity.dart';
|
import 'package:star_lock/mine/minePersonInfo/minePersonInfoEditAccount/minePersonInfoEditAccount/mineUnbindPhoneOrEmail_entity.dart';
|
||||||
import 'package:star_lock/network/api_repository.dart';
|
import 'package:star_lock/network/api_repository.dart';
|
||||||
import 'package:star_lock/tools/NativeInteractionTool.dart';
|
|
||||||
import 'package:star_lock/tools/baseGetXController.dart';
|
import 'package:star_lock/tools/baseGetXController.dart';
|
||||||
import 'package:star_lock/tools/push/message_management.dart';
|
import 'package:star_lock/tools/push/message_management.dart';
|
||||||
import 'package:star_lock/tools/push/notification_service.dart';
|
import 'package:star_lock/tools/push/notification_service.dart';
|
||||||
@ -27,7 +23,7 @@ class XSJPushProvider {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
print('jPushKey ${F.jPushKey}');
|
AppLog.log('jPushKey ${F.jPushKey}');
|
||||||
// final String? bundleIdentifier =
|
// final String? bundleIdentifier =
|
||||||
// await NativeInteractionTool().getBundleIdentifier();
|
// await NativeInteractionTool().getBundleIdentifier();
|
||||||
// print('bundleIdentifier: $bundleIdentifier');
|
// print('bundleIdentifier: $bundleIdentifier');
|
||||||
@ -46,7 +42,7 @@ class XSJPushProvider {
|
|||||||
AppLog.log('JPush initialized.');
|
AppLog.log('JPush initialized.');
|
||||||
|
|
||||||
final String rid = await jpush.getRegistrationID();
|
final String rid = await jpush.getRegistrationID();
|
||||||
print('flutter get registration id : $rid');
|
AppLog.log('flutter get registration id : $rid');
|
||||||
pushBindDeviceID(rid);
|
pushBindDeviceID(rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +51,7 @@ class XSJPushProvider {
|
|||||||
jpush.addEventHandler(
|
jpush.addEventHandler(
|
||||||
onReceiveNotification: (Map<String, dynamic> message) async {
|
onReceiveNotification: (Map<String, dynamic> message) async {
|
||||||
AppLog.log('onReceiveNotification: $message');
|
AppLog.log('onReceiveNotification: $message');
|
||||||
// 这里可以用 flutter_local_notifications 自定义通知样式
|
// showCustomNotification(message);
|
||||||
showCustomNotification(message);
|
|
||||||
},
|
},
|
||||||
onOpenNotification: (Map<String, dynamic> message) async {
|
onOpenNotification: (Map<String, dynamic> message) async {
|
||||||
AppLog.log('onOpenNotification: $message');
|
AppLog.log('onOpenNotification: $message');
|
||||||
@ -86,16 +81,6 @@ class XSJPushProvider {
|
|||||||
// Remove the incorrect addEventHandler call
|
// Remove the incorrect addEventHandler call
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showCustomNotification(Map<String, dynamic> message) async {
|
|
||||||
final String title = message['notification']['android']['title'] ?? '默认标题';
|
|
||||||
final String content =
|
|
||||||
message['notification']['android']['alert'] ?? '默认内容';
|
|
||||||
final String imageUrl = message['notification']['android']['extras']
|
|
||||||
?['image_url']; // 从 extras 获取图片
|
|
||||||
|
|
||||||
NotificationService().showImageNotification(title, content, imageUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> pushBindDeviceID(String deviceID) async {
|
Future<void> pushBindDeviceID(String deviceID) async {
|
||||||
try {
|
try {
|
||||||
if (deviceID.isEmpty) {
|
if (deviceID.isEmpty) {
|
||||||
@ -118,22 +103,12 @@ class XSJPushProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//本地通知初始化 isCancelLocalPush 是否取消所有本地通知
|
void showCustomNotification(Map<String, dynamic> data) {
|
||||||
Future<void> initLocalNotification({required bool isCancelLocalPush}) async {
|
final String title = data['notification']['android']['title'] ?? '默认标题';
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
final String content = data['notification']['android']['alert'] ?? '默认内容';
|
||||||
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
final String imageUrl = data['notification']['android']['extras']
|
||||||
FlutterLocalNotificationsPlugin();
|
?['image_url']; // 从 extras 获取图片
|
||||||
|
|
||||||
if (Platform.isAndroid) {
|
NotificationService().showImageNotification(title, content, imageUrl);
|
||||||
const AndroidInitializationSettings initializationSettingsAndroid =
|
|
||||||
AndroidInitializationSettings('app_icon');
|
|
||||||
const InitializationSettings initializationSettings =
|
|
||||||
InitializationSettings(android: initializationSettingsAndroid);
|
|
||||||
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isCancelLocalPush) {
|
|
||||||
await flutterLocalNotificationsPlugin.cancelAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user