Flutterオーロラプッシュandroid実現
5337 ワード
Flutter集積オーロラプッシュ
現在、多くのプッシュメーカーはオーロラだけがflutterをサポートしています.サポートしてください.くだらないことは言わないで、コードを引っ張り始めます
最初のステップ
デバイスの原因で現在アンドロイドでテストに成功しているだけなので、まずアンドロイドの構成過程を共有し、まずオーロラ公式サイトでアプリケーションを作成し、完了したらandroid/app/build.gradleファイルの下に構成を追加します.
manifestPlaceholders = [
JPUSH_PKGNAME : " ",
JPUSH_APPKEY : "38a101c09adf57ef70eda9be", // NOTE: JPush Appkey.
JPUSH_CHANNEL : "developer-default", // .
]
dependencies:
flutter:
sdk: flutter
flutter_jpush: ^0.0.4
import 'package:flutter/material.dart';
import 'package:flutter_jpush/flutter_jpush.dart';
import 'jpushpage.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
_startupJpush();
_ReceiveNotification();
_OpenNotification();
_ReceiveCustomMsg();
}
void _startupJpush() async {
print(" jpush");
await FlutterJPush.startup();
print(" jpush ");
}
/*
*
* */
void _ReceiveNotification() async {
FlutterJPush.addReceiveNotificationListener(
(JPushNotification notification) {
setState(() {
///
print(" : $notification");
});
});
}
/*
*
* */
void _ReceiveCustomMsg() async {
FlutterJPush.addReceiveCustomMsgListener((JPushMessage msg) {
setState(() {
print(" : $msg");
});
});
}
/*
*
* */
void _OpenNotification() async {
FlutterJPush.addReceiveOpenNotificationListener(
(JPushNotification notification) {
setState(() {
print(" : $notification");
Navigator.push(context,MaterialPageRoute(builder: (context){
return jpushPage();
})).then((String value){
});
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}