首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >即时通信IM接入华为离线推送时,注册的广播无法收到token?

即时通信IM接入华为离线推送时,注册的广播无法收到token?

提问于 2019-10-09 14:44:30
回答 0关注 0查看 681

HUAWEIPushReceiver

代码语言:java
复制
public class HUAWEIPushReceiver extends PushReceiver {
    private static final String TAG = "HUAWEIPushReceiver";

    @Override
    public void onToken(Context context, String token, Bundle extras) {
        Log.i(TAG, "onToken:" + token);
        ThirdPushTokenMgr.getInstance().setThirdPushToken(token);  // token 在此处传入,后续推送信息上报时需要使用
        ThirdPushTokenMgr.getInstance().setPushTokenToTIM();
    }
}

在调用了HMSAgent.init(this)后,发现在HUAWEIPushReceiver广播接收器这里收不到返回的token,导致无法上传。

测试机型为华为Android 8.0、9.0的手机。

AndroidManifest.xml

代码语言:xml
复制
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.smart_talk">

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


    <!--HMS-SDK 引导升级 HMS 功能,访问 OTA 服务器需要网络权限-->
    <uses-permission android:name="android.permission.INTERNET" />
    <!--HMS-SDK 引导升级 HMS 功能,保存下载的升级包需要 SD 卡写权限-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!--检测网络状态-->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <!--检测 Wi-Fi 状态-->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <!--为了获取用户手机的 IMEI,用来唯一的标识用户。-->
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <!--如果是Android 8.0,应用编译配置的 targetSdkVersion>=26,请务必添加以下权限 -->
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

    <!--这里的 com.tencent.qcloud.tim.tuikit 改成您的 App 的包名-->
    <permission
        android:name="com.example.smart_talk.permission.PROCESS_PUSH_MSG"
        android:protectionLevel="signatureOrSystem"/>
    <uses-permission android:name="com.example.smart_talk.permission.PROCESS_PUSH_MSG" />
    <!--这里的 com.tencent.qcloud.tim.tuikit 改成您的 App 的包名-->

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        tools:replace="android:label"
        android:label="Smart Talk"
        android:icon="@mipmap/logo">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name="com.yalantis.ucrop.UCropActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

        <activity
            android:name="com.huawei.hms.activity.BridgeActivity"
            android:configChanges="orientation|locale|screenSize|layoutDirection|fontScale"
            android:excludeFromRecents="true"
            android:exported="false"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.Translucent" >
            <meta-data
                android:name="hwc-theme"
                android:value="androidhwext:style/Theme.Emui.Translucent" />
        </activity>

        <activity
            android:name="com.huawei.updatesdk.service.otaupdate.AppUpdateActivity"
            android:configChanges="orientation|screenSize"
            android:exported="false"
            android:theme="@style/upsdkDlDialog" >

            <meta-data
                android:name="hwc-theme"
                android:value="androidhwext:style/Theme.Emui.Translucent.NoTitleBar" />
        </activity>

        <activity
            android:name="com.huawei.updatesdk.support.pm.PackageInstallerActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:exported="false"
            android:theme="@style/upsdkDlDialog" >
            <meta-data
                android:name="hwc-theme"
                android:value="androidhwext:style/Theme.Emui.Translucent" />
        </activity>

        <activity
            android:name="com.huawei.android.hms.agent.common.HMSAgentActivity"
            android:configChanges="orientation|locale|screenSize|layoutDirection|fontScale"
            android:excludeFromRecents="true"
            android:exported="false"
            android:hardwareAccelerated="true"
            android:theme="@android:style/Theme.Translucent" >
            <meta-data
                android:name="hwc-theme"
                android:value="androidhwext:style/Theme.Emui.Translucent" />
        </activity>

        <meta-data
            android:name="com.huawei.hms.client.appid"
            android:value="appid=101157661"/> <!--这里的 appid 值修改为您的华为推送 App ID-->
        <provider
            android:name="com.huawei.hms.update.provider.UpdateProvider"
            android:authorities="com.example.smart_talk.hms.update.provide"
            android:exported="false"
            android:grantUriPermissions="true"/>
        <provider
            android:name="com.huawei.updatesdk.fileprovider.UpdateSdkFileProvider"
            android:authorities="com.example.smart_talk.updateSdk.fileProvider"
            android:exported="false"
            android:grantUriPermissions="true">
        </provider>

        <!-- 应用下载服务 -->
        <service android:name="com.huawei.updatesdk.service.deamon.download.DownloadService"
            android:exported="false"/>

        <service
            android:name="com.huawei.hms.support.api.push.service.HmsMsgService"
            android:enabled="true"
            android:exported="true"
            android:process=":pushservice">
            <intent-filter>
                <action android:name="com.huawei.push.msg.NOTIFY_MSG" />
                <action android:name="com.huawei.push.msg.PASSBY_MSG" />
            </intent-filter>
        </service>

        <!--这里的 com.tencent.qcloud.tim.demo.thirdpush.HUAWEIPushReceiver 修改成您 App 中的完整类名-->
        <receiver android:name="com.example.smart_talk.HUAWEIPushReceiver"
            android:permission="com.example.smart_talk.permission.PROCESS_PUSH_MSG">
            <intent-filter>
                <!-- 必须,用于接收 token -->
                <action android:name="com.huawei.android.push.intent.REGISTRATION" />
                <!-- 必须, 用于接收透传消息 -->
                <action android:name="com.huawei.android.push.intent.RECEIVE" />
                <!-- 必须, 用于接收通知栏消息点击事件 此事件不需要开发者处理,只需注册就可以-->
                <action android:name="com.huawei.intent.action.PUSH_DELAY_NOTIFY"/>
            </intent-filter>
        </receiver>

    </application>
</manifest>

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档