1、配置極光開發者html
1.註冊極光開發者android
https://www.jiguang.cn/pushapp
2.建立應用async
2、建立APPide
1.添加依賴 測試
pubspec.yaml 添加: flutter_jpush: ^0.0.4
ui
2.android 專屬配置spa
defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "xxx" minSdkVersion 16 targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" ndk { //選擇要添加的對應 cpu 類型的 .so 庫。 abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64' // 'arm64-v8a', } manifestPlaceholders = [ JPUSH_PKGNAME : applicationId, JPUSH_APPKEY : "123", //JPush上註冊的包名對應的appkey. JPUSH_CHANNEL : "developer-default",//你的推送渠道,若是不知道填寫developer-default便可 ] }
3.編寫代碼3d
import 'package:flutter/material.dart'; import 'package:flutter_jpush/flutter_jpush.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { void initState(){ super.initState(); _initJPush(); _initNotification(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text("測試"), ), body: Center( child: Text('data'), )), ); } //初始化 void _initJPush() async { await FlutterJPush.startup(); print("初始化jpush成功"); // 獲取 registrationID var registrationID = await FlutterJPush.getRegistrationID(); print(registrationID); // 註冊接收和打開 Notification() _initNotification(); } //初始化 void _initNotification() async { FlutterJPush.addReceiveNotificationListener( (JPushNotification notification) { print("收到推送提醒: $notification"); }); FlutterJPush.addReceiveOpenNotificationListener( (JPushNotification notification) { print("打開了推送提醒: $notification"); }); } }
測試code
推送通知
注意:android必定要加上包名,並且一旦確認不能更改