因为自己写的读书app flutor写的笔趣各源app选择继续发布版本,将包放在QQ组,所以使用消息告诉QQ组更新版本。
flutter目前只有极光推出了插件。- 初始化JPush
//github 集成
dependencies:
jpush_flutter:
git:
url: gi
ref: master
// pub 集成
dependencies:
jpush_flutter: 0.5.3
- 在 /android/a 中添加下列代码,(注意当你拆分打包,下面ndk选项可能会报错,应当删除,当然,还是要具体实践)
android: {
....
defaultConfig {
applicationId "替换成自己应用 ID"
...
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a',
}
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "appkey", // NOTE: JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
}
- 需要先调用 JPu 来初始化插件,才能保证其他功能正常工作。
String debugLable = 'Unknown';
final JPush jpush = new JPush();
@override
void initState() {
();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
try {
j(
onReceiveNotification: (Map<String, dynamic> message) async {
print("flutter onReceiveNotification: $message");
setState(() {
debugLable = "flutter onReceiveNotification: $message";
});
}, onOpenNotification: (Map<String, dynamic> message) async {
print("flutter onOpenNotification: $message");
setState(() {
debugLable = "flutter onOpenNotification: $message";
});
}, onReceiveMessage: (Map<String, dynamic> message) async {
print("flutter onReceiveMessage: $message");
setState(() {
debugLable = "flutter onReceiveMessage: $message";
});
}, onReceiveNotificationAuthorization:
(Map<String, dynamic> message) async {
print("flutter onReceiveNotificationAuthorization: $message");
setState(() {
debugLable = "flutter onReceiveNotificationAuthorization: $message";
});
});
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
jpu(
appKey: "e58a32cb3e4469ebf31867e5", //你自己应用的 AppKey
channel: "theChannel",
production: false,
debug: true,
);
j(
new NotificationSettingsIOS(sound: true, alert: true, badge: true));
// Platform messages may fail, so we use a try/catch PlatformException.
j().then((rid) {
print("flutter get registration id : $rid");
setState(() {
debugLable = "flutter getRegistrationID: $rid";
});
});
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
debugLable = platformVersion;
});
}
- 至此client配置基本完成,下面到极光官网注册账号,进入开发者平台
创建应用
点击推送
点击发送通知
client就可以看见通知
点击消息转到QQ中,导入url_launcher
}, onOpenNotification: (Map<String, dynamic> message) async {
/// 吊起QQ
/// [number]QQ号
/// [isGroup]是否是群号,默认是,不是群号则直接跳转聊天
callQQ();
print("flutter onOpenNotification: $message");
setState(() {
debugLable = "flutter onOpenNotification: $message";
});
void callQQ({int number = 953457248, bool isGroup = true}) async {
String url = isGroup
? 'mqqapi://card/show_pslcard?src_type=internal&version=1&uin=${number ?? 0}&card_type=group&source=qrcode'
: 'mqqwpa://im/chat?chat_type=wpa&uin=${number ?? 0}&version=1&src_type=web&web_src=oicqzone.com';
if (await canLaunch(url)) {
await launch(url);
} else {
print('不能访问');
}
}
点击消息即可转到QQ