Android混合推送: 华为推送 注册失败

日志:

E/===AVOS Cloud===: LogUtil$avlog->e->39: receiver com.huawei.android.pushagent.PushBootReceiver is missing!

排错: manifest里已经做如下配置

 <receiver
        android:name="com.huawei.android.pushagent.PushBootReceiver"
        android:process=":pushservice" >
        <intent-filter>
            <action android:name="com.huawei.android.push.intent.REGISTER" />
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        </intent-filter>
        <meta-data
            android:name="CS_cloud_version"
            android:value="\u0032\u0037\u0030\u0035" />
    </receiver>

而且点进去 确实有PushBootReceiver这个类.

package com.huawei.android.pushagent;

import android.content.Context;
import android.content.Intent;
import com.huawei.android.pushagent.PushEventReceiver;
import com.huawei.android.pushagent.c.a;
import com.huawei.android.pushagent.c.a.e;

public class PushBootReceiver extends PushEventReceiver {
    public PushBootReceiver() {
    }

    public void onReceive(Context var1, Intent var2) {
        int var3 = a.q(var1);
        e.a("PushLogAC2705", "voteState:" + var3);
        if(2 == var3) {
            a.a(var1, false);
        } else {
            super.onReceive(var1, var2);
        }

    }
}


求大神解答..,,

你好,是不是你的 PushBootReceiver 没有写进 application 标签里?

具体可以定位到以下代码报异常: android.content.pm.PackageManager$NameNotFoundException

context.getPackageManager().getReceiverInfo(new ComponentName(this, PushBootReceiver.class), 0);

确实写进去了, 因为测试 其他receiver都不报这个异常
看下完整的manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.wangzhenxing.shotcutdemo">

    <uses-permission android:name="android.permission.INTERNET"/>
    <!--检测网络状态。-->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <!--保存离线报告的缓存数据。-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <!--唯一标示: 获取用户手机的 IMEI -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <!--唯一标示: 获取wifi mac地址-->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <!--获取客户端 crash log, 将 crash log 汇报到服务器上 -->
    <uses-permission android:name="android.permission.READ_LOGS" />
    <!--huawei push config-->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <!--统计渠道信息-->
        <meta-data android:name="leancloud" android:value="360助手"/>
        <meta-data android:name="app_id_mi" android:value="_2882303761517497192"/>
        <meta-data android:name="app_key_mi" android:value="_5351749760192"/>

        <activity android:name=".activity.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <service android:name="com.avos.avoscloud.PushService"/>

        <receiver android:name="com.avos.avoscloud.AVBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <!--代替SCREEN_ON和SCREEN_OFF, 解锁广播-->
                <action android:name="android.intent.action.USER_PRESENT"/>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
            </intent-filter>
        </receiver>
        <receiver android:name=".receiver.CustomReceiver" android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.USER_PRESENT"/>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
                <action android:name="MDXIM_STATUS"/>
            </intent-filter>
        </receiver>

        <activity android:name=".activity.Laptop">
        </activity>
        <activity android:name=".activity.PhoneList">
        </activity>
        <activity android:name=".activity.PushCenter">
        </activity>
        <activity
            android:name=".activity.BaseActivity"
            android:label="@string/title_activity_base"
            android:theme="@style/AppTheme.NoActionBar">
        </activity>
        <!--huawei push config-->
        <!-- 必须,用于华为 Android 6.0 系统的动态权限页面-->
        <activity android:name="com.huawei.android.pushselfshow.permission.RequestPermissionsActivity"/>

        <receiver android:name="com.avos.avoscloud.AVHwPushMessageReceiver" >
            <intent-filter>
                <!-- 必须,用于接收 token -->
                <action android:name="com.huawei.android.push.intent.REGISTRATION" />
                <!-- 必须,用于接收消息 -->
                <action android:name="com.huawei.android.push.intent.RECEIVE" />
                <!-- 可选,用于点击通知栏或通知栏上的按钮后触发 onEvent 回调 -->
                <action android:name="com.huawei.android.push.intent.CLICK" />
                <!-- 可选,查看 push 通道是否连接,不查看则不需要 -->
                <action android:name="com.huawei.intent.action.PUSH_STATE" />
            </intent-filter>
        </receiver>

        <receiver
            android:name="com.huawei.android.pushagent.PushEventReceiver"
            android:process=":pushservice" >
            <intent-filter>
                <action android:name="com.huawei.android.push.intent.REFRESH_PUSH_CHANNEL" />
                <action android:name="com.huawei.intent.action.PUSH" />
                <action android:name="com.huawei.intent.action.PUSH_ON" />
                <action android:name="com.huawei.android.push.PLUGIN" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
                <data android:scheme="com.example.wangzhenxing.shotcutdemo" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.huawei.android.pushagent.PushBootReceiver"
            android:process=":pushservice" >
            <intent-filter>
                <action android:name="com.huawei.android.push.intent.REGISTER" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
            <meta-data
                android:name="CS_cloud_version"
                android:value="\u0032\u0037\u0030\u0035" />
        </receiver>

        <service
            android:name="com.huawei.android.pushagent.PushService"
            android:process=":pushservice" >
        </service>

    </application>

</manifest>

自带的推送和小米推送测试都没问题, 目前就是华为这个有问题, 可否给个demo 参考下呢? 谢谢!!

测试机: honor H60-L03 EMUI3.0

用你这个demo测试, 同样出现了这个问题. 而且是偶发性的:

cn.leancloud.mixpush E/===AVOS Cloud===: LogUtil$avlog->e->39: receiver com.huawei.android.pushagent.PushBootReceiver is missing!
cn.leancloud.mixpush E/===AVOS Cloud===: LogUtil$avlog->e->39: register error, mainifest is incomplete!

log如下时, 也会注册失败(数据库vendor字段为空):

I/PushLog: [main-1]framework push exist, use framework push first(/null:-1)

注册成功时候, log信息如下:

cn.leancloud.mixpush I/PushLog: [main-1]framework push exist, use framework push first(/null:-1)
cn.leancloud.mixpush I/PushLog: [main-1]push client begin to receive the token(/null:-1)

对, 还有个需要提醒的是, demo 清单 里少了这个.

<uses-permission android:name="android.permission.WAKE_LOCK" />

注册huawei push的时候会check这个permission

感谢提醒,已更新 WAKE_LOCK 权限。

偶发的 receiver com.huawei.android.pushagent.PushBootReceiver is missing! 我会继续调查,有进展会更新回复。

继续折腾.....
用这个demo测试, 只把appID 和key换成我自己的, 方便进入数据库查看,...测试结果 -> 华为推送注册成功(vendor字段: hw)

我新建的project, 将这个demo所有代码 完完全全移植过去(除了 包名不一样其他完全一样), 测试结果 -> 华为推送注册失败(vendor字段为空);

然后, 我把我的project 包名改为cn.leancloud.mixpush (在gradle中修改 applicationId), 测试结果 -> 华为推送注册成功 !
继续测试, 发现 包名必须与 cn.leancloud.mixpush 完完全全一样才行;

这个是神马逻辑啊?????

以下是抓包分析: 如果可以注册成功, 则会有以下两个req

第一张是打开app 注册到leancloud (上面是request, 下面是response)

第二张 是点击 注册华为推送

把包名改为cn.leancloud.mixpush是可以注册成功的, 也就是说会有第二个的request
如果包名不是这个, 那么第二个request根本不会发起......醉了

你好,我也遇到这个问题,请问是什么原因导致了,要怎么解决呢

我这边还是无解中....
只能先集成小米了......

是否可以私信,发下你的 demo 给我?我来调查下。

点我头像可以发私信。

你们提供的demo也自己会报receiver com.huawei.android.pushagent.PushBootReceiver is missing! 这个错误。
还有这个配置应该是华为AppSecret吧,华为没有提供AppKey:

我这边运行 demo 没有报 com.huawei.android.pushagent.PushBootReceiver is missing! 这个错。

华为的这个 App Secret 文字已在更正中,感谢提醒。

华为荣耀V9也碰到这个问题。配置肯定是无误的,请问这个问题现在有解决吗?

在 4.4.3 中对相关逻辑进行了处理,请升级一下看看是否还有问题。

的确先前的错误警告没了,可是明明进入的是registerHuaweiPush,怎么抛出的异常似乎和魅族api有关 disappointed_relieved

我可以确定进入了下图红色标识区域

红框里的 requestToken 代码部分,就是开始去注册华为的过程。除了您贴的日志,还有其他的报错日志吗?

或者可以发我一个项目,我来帮你看看。点我头像私信。