flutterupushplugin 0.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 39

UmengPush Flutter Plugin #

安装 #

在工程 pubspec.yaml 中加入 dependencies

dependencies:
  flutterupushplugin: ^0.0.4

配置 #

Android: #

第一步: #

android/app/build.gradle中添加下列代码:

注意manifestPlaceholders里面的值格式一定是:@xxxxxx,@不能省略,省略了就会注册失败。

android: {
  ....
  defaultConfig {
    applicationId "替换成自己应用 ID"
    ...
  manifestPlaceholders = [
                UMENG_APPKEY : "@替换成UMENG_APPKEY",
                UMENG_MESSAGE_SECRET : "@替换成UMENG_MESSAGE_SECRET",
                UMENG_CHANNEL : "UMENG",
                XIAOMI_APPID : "@替换成XIAOMI_APPID",
                XIAOMI_APPKEY : "@替换成XIAOMI_APPKEY",
                VIVO_APPKEY : "@替换成VIVO_APPKEY",
                VIVO_APPID : "@替换成VIVO_APPID",
                OPPO_APPSECRET : "@替换成OPPO_APPSECRET",
                OPPO_APPKEY : "@替换成OPPO_APPKEY",
                HUAWEI_APPID :"@替换成HUAWEI_APPID",
                MEIZU_APPID :"@替换成MEIZU_APPID",
                MEIZU_APPKEY : "@替换成MEIZU_APPKEY"
        ]
  }
}

如果没有申请某个厂商通道,就不用配置,例如:没有申请OPPO推送,就放空处理

android: {
  ....
  defaultConfig {
    applicationId "替换成自己应用 ID"
    ...
  manifestPlaceholders = [
                UMENG_APPKEY : "@替换成UMENG_APPKEY",
                UMENG_MESSAGE_SECRET : "@替换成UMENG_MESSAGE_SECRET",
                UMENG_CHANNEL : "UMENG",
                XIAOMI_APPID : "@替换成XIAOMI_APPID",
                XIAOMI_APPKEY : "@替换成XIAOMI_APPKEY",
                VIVO_APPKEY : "@替换成VIVO_APPKEY",
                VIVO_APPID : "@替换成VIVO_APPID",
                OPPO_APPSECRET : "",//没有申请OPPO推送,就放空处理
                OPPO_APPKEY : "",//没有申请OPPO推送,就放空处理
                HUAWEI_APPID :"@替换成HUAWEI_APPID",
                MEIZU_APPID :"@替换成MEIZU_APPID",
                MEIZU_APPKEY : "@替换成MEIZU_APPKEY"
        ]
  }
}

第二步: #

1.主项目的启动类一定要要继承 UPushMainActivty,例如:

public class MainActivity extends UPushMainActivty  {

}

2.自定义Recevier组件受魅族接入方式限制,必须在包名目录实现一个自定义Recevier,继承自MeizuPushReceiver,例如:

public class MeizuTestReceiver extends MeizuPushReceiver {

}

然后在AndroidManifest.xml中配置该Recevier,例如:

<!--魅族push应用定义消息receiver声明 -->
<receiver android:name="${applicationId}.MeizuTestReceiver">
        <intent-filter>
            <!-- 接收push消息 -->
            <action android:name="com.meizu.flyme.push.intent.MESSAGE" />
            <!-- 接收register消息 -->
            <action android:name="com.meizu.flyme.push.intent.REGISTER.FEEDBACK" />
            <!-- 接收unregister消息-->
            <action android:name="com.meizu.flyme.push.intent.UNREGISTER.FEEDBACK" />
            <!-- 兼容低版本Flyme3推送服务配置 -->
            <action android:name="com.meizu.c2dm.intent.REGISTRATION" />
            <action android:name="com.meizu.c2dm.intent.RECEIVE" />
            <category android:name="${applicationId}"></category>
        </intent-filter>
</receiver>

3. 厂商对后台进程做了诸多限制。若使用一键清理,应用的channel进程被清除,将接收不到推送。为了增加推送的送达率,接入厂商托管弹窗功能。通知将由厂商系统托管弹出,点击通知栏将跳转到指定的Activity。该Activity需继承自UPushOffLineNotificationActivity,例如: #

public class MipushTestActivity extends UPushOffLineNotificationActivity {

}

然后在AndroidManifest.xml中配置该 MipushTestActivity,例如:

  <activity
            android:name="${applicationId}.MipushTestActivity"
            android:launchMode="singleTask"
            android:exported="true"/>

4.做SDK代码初始化工作,所以自定义的Application需集成 UPushApplication,例如: #

public class MyApplication extends UPushApplication {

}

然后在AndroidManifest.xml中配置该MyApplication,例如:

<manifest>
 ...
    <application
        android:name="替换成自己应用的包名.MyApplication"
       >
</manifest>

注册成功标记 #

小米Push通道
注册成功后会在tag:MiPushBroadcastReceiver下面打印log: onCommandResult is called. regid= xxxxxxxxxxxxxxxxxxxxxxx接收到小米消息则会打印log: onReceiveMessage,msg= xxxxxxxxxxxxxxxxxxxxxxx
华为Push通道
注册成功后会在tag:HuaWeiReceiver下面打印log: 获取token成功,token= xxxxxxxxxxxxxxxxxxxxxxx接收到华为消息则会打印log: HuaWeiReceiver,content= xxxxxxxxxxxxxxxxxxxxxxx

魅族Push通道
注册成功后会在tag:tag:MeizuPushReceiver下面打印log: onRegister, pushId=xxxxxxxxxxxxxxxxxxxxxxx
OPPO厂商通道
是否注册成功, 可以通过过滤OppoPush关键字查看, 注册成功会打印onRegister regid=**相关日志, 否则检查参数是否正确填入
vivo Push通道
是否注册成功, 可以通过过滤PushMessageReceiver关键字查看

详细后台配置可以看 友盟配置文档 #

iOS: 在完善中 #

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutterupushplugin/u_push_plugin.dart';
import 'package:flutterupushplugin/u_push_options.dart';
import 'package:flutterupushplugin_example/test_page.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  int index=0;
  GlobalKey key;
  var  mapview1=null;
  UpushPlugin mUpushPlugin = UpushPlugin();
  String result = "返回消息提示";
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    //消息的回调
    mUpushPlugin.addEventHandle(
        onReceiveCustomMessage: (Map<String, dynamic> event) {
          setState(() {
            result = "用户自定义消息内容: ${event} ";
          });
        },
        onReceiveNotification: (Map<String, dynamic> event) {


          setState(() {
            result ="在线接收通知"+ event.toString();
          });
        },
        onReceiveOffLineNotification: (Map<String, dynamic> event) {
          setState(() {
            result = "离线通知:"+event.toString();
          });
        });

  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(

        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body:Center(
          child: Column(
            children: <Widget>[
              Text("返回结果:" + result),
              RaisedButton(
                onPressed: () {
                  mUpushPlugin.addTags(["tags1", "tags2"]).then((value) {
                    debugPrint(" 添加标签 ${value} ");
                    setState(() {
                      result = " 添加标签  结果:${value} ";
                    });
                  });
                },
                child: Text("添加标签   tags1, tags2"),
              ),
              RaisedButton(
                onPressed: () {
                  mUpushPlugin.deleteTags(["tags1", "tags2"]).then((value) {
                    debugPrint(" 删除标签 结果:${value} ");
                    setState(() {
                      result = " 删除标签 结果:${value} ";
                    });
                  });
                },
                child: Text("删除标签  tags1, tags2"),
              ),
              RaisedButton(
                onPressed: () {
                  mUpushPlugin.getTags().then((value) {
                    debugPrint(" 获取标签  结果:${value} ");
                    setState(() {
                      result = " 获取标签 结果:${value} ";
                    });
                  });
                },
                child: Text("获取标签"),
              ),
              RaisedButton(
                onPressed: () {
                  mUpushPlugin.addAlias("flutter","android").then((value) {
                    debugPrint(" 添加别名  结果:${value} ");
                    setState(() {
                      result = " 添加别名 结果:${value} ";
                    });
                  });
                },
                child: Text("同时添加别名 flutter,android"),
              ),
              RaisedButton(
                onPressed: () {
                  mUpushPlugin.setAlias("flutter","ios").then((value) {
                    debugPrint(" 设置别名  结果:${value} ");
                    setState(() {
                      result = " 设置别名  结果:${value} ";
                    });
                  });
                },
                child: Text("同时设置别名 flutter,ios"),
              ),
              RaisedButton(
                onPressed: () {
                  mUpushPlugin.deleteAlias("flutter","ios").then((value) {
                    debugPrint(" 删除别名 结果:${value} ");
                    setState(() {
                      result = " 删除别名 结果:${value} ";
                    });
                  });
                },
                child: Text("同时删除别名 flutter,ios "),
              ),
              RaisedButton(
                onPressed: () {
                  mUpushPlugin.getRegistrationId().then((value) {
                    debugPrint(" 获取注册id ${value} ");
                    setState(() {
                      result = " 获取注册id ${value} ";
                    });
                  });
                },
                child: Text("获取注册id "),
              ),
            ],
          ),
        )


        ,
      ));
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutterupushplugin: ^0.0.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutterupushplugin/register_info.dart';
import 'package:flutterupushplugin/u_push_options.dart';
import 'package:flutterupushplugin/u_push_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
6
Health:
Code health derived from static analysis. [more]
86
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
39
Learn more about scoring.

We analyzed this package on Jul 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:flutterupushplugin/register_info.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:flutterupushplugin/register_info.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:flutterupushplugin/register_info.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:flutterupushplugin/register_info.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [flutterupushplugin] that is in a package requiring null.

Health suggestions

Fix lib/u_push_options.dart. (-6.78 points)

Analysis of lib/u_push_options.dart reported 14 hints, including:

line 1 col 8: Unused import: 'dart:convert'.

line 3 col 8: Unused import: 'package:flutter/services.dart'.

line 6 col 1: Prefer using /// for doc comments.

line 10 col 15: Name non-constant identifiers using lowerCamelCase.

line 11 col 15: Name non-constant identifiers using lowerCamelCase.

Fix lib/u_push_plugin.dart. (-5.84 points)

Analysis of lib/u_push_plugin.dart reported 12 hints, including:

line 5 col 8: Unused import: 'package:flutterupushplugin/register_info.dart'.

line 34 col 16: Don't explicitly initialize variables to null.

line 37 col 16: Don't explicitly initialize variables to null.

line 40 col 16: Don't explicitly initialize variables to null.

line 43 col 16: Don't explicitly initialize variables to null.

Fix lib/register_info.dart. (-1.99 points)

Analysis of lib/register_info.dart reported 4 hints:

line 1 col 8: Unused import: 'dart:convert'.

line 3 col 8: Unused import: 'package:flutter/services.dart'.

line 4 col 8: Unused import: 'package:flutter/widgets.dart'.

line 6 col 1: Prefer using /// for doc comments.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the description field in your package's pubspec.yaml field should primarily contain characters used in English.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test