当前位置:网站首页>Manufacturer Push Platform-Huawei Access
Manufacturer Push Platform-Huawei Access
2022-08-11 06:34:00 【rest of my life love static】
Huawei's push official document
About the process I would not be in here,Explain the main access to the process as possible problems.
第一、下载HMS SDK Agent套件(必选)
1.1 Download from the website to suite later,解压文件后,You will see the catalog(copysrc是后面生成的,可以忽略)
1.2 执行GetHMSAgent.bat脚本,According to the script prompt and his needs,会生成copysrc文件夹
1.3 然后把copysrcCopies of the content inside to project their own press
1.4 在Application里面进行初始化
String manufacturer = android.os.Build.MANUFACTURER;
LogUtils.i(TAG, "Mobile phone manufacturer information:" + manufacturer);
//华为推送
if ("huawei".equals(manufacturer.toLowerCase()) || "honor".equals(manufacturer.toLowerCase())) {
if (getHuaWeiEmui() >= 9) {
HMSAgent.init(this);
return;
}
}
/**
* EMUIThe version number judgment as follows:(判断emuiApiLevel>=9即可)
*
* @return
*/
private int getHuaWeiEmui() {
int emuiApiLevel = 0;
try {
Class cls = Class.forName("android.os.SystemProperties");
Method method = cls.getDeclaredMethod("get", new Class[]{String.class});
emuiApiLevel = Integer.parseInt((String) method.invoke(cls, new Object[]{"ro.build.hw_emui_api_level"}));
} catch (Exception e) {
e.printStackTrace();
}
return emuiApiLevel;
}
第二、Manifest的配置
2.1、在生成的copysrc文件夹下,Already help you generate relatedmanifest的配置信息了
2.2、If it is a single point to push,You can specify a push goalstoken,那这个token从哪里获取呢?This is you need us to achievePushReceiver.At the same time also need our inManifest里面进行配置
public class HuaWeiPushReceiver extends PushReceiver {
private static final String TAG=HuaWeiPushReceiver.class.getCanonicalName();
/**
* 供子类继承,用来接收token
*Developers to realizeToken保存逻辑.
* @param context 上下文信息
* @param token push token
* @param extras 附加信息
*/
@Override
public void onToken(Context context, String token, Bundle extras) {
super.onToken(context, token, extras);
LogUtils.i(TAG,"onToken:"+token);
PreferenceImpl.getPreference(context).put(CacheConstants.PUSH_REGISTER_ID,token);
}
}
<receiver
android:name=".receiver.HuaWeiPushReceiver"
android:permission="包名.permission.PROCESS_PUSH_MSG">
<intent-filter>
<!-- 必须,用于接收token -->
<action android:name="com.huawei.android.push.intent.REGISTRATION" />
<!-- 必须, Used to receive passthrough message -->
<action android:name="com.huawei.android.push.intent.RECEIVE" />
<!-- 必须, Used to receive notification bar message click event This event does not need to deal with the developers,Just register can be-->
<action android:name="com.huawei.intent.action.PUSH_DELAY_NOTIFY" />
</intent-filter>
</receiver>
第三、Click on the notification behavior
3.1、From the server configuration field in send a notification that,可以看到,点击通知后,Supports three behavior(1、自定义;2、指定URL;3、APP首页),我们常用的是第一个,自定义.
3.1.1 自定义的话,You need to client generationintent内容
In the client to execute the following code and print outintentUri值,然后把生成的intentUriThe string to the server can be.
Intent intent = new Intent();
intent.setClass(MainActivity.this, 要跳转的Activity);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("ext1","helloExt1");
intent.putExtra("ext2","helloExt2");
String intentUri = intent.toUri(Intent.URI_INTENT_SCHEME);
manifest中 In the designated registrationActivity的地方(就是ActivityA)加上.
<intent-filter>
<action android:name="android.app.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data //也可以通过scheme方式启动
android:scheme="customscheme"
android:host="com.huawei.pushtest"
android:path="/notify_detail"/>
</intent-filter>
Also need to addandroid:launchMode="singleTask"来配合newIntentTo use repeatedly receivingIntent.
If you want to make the server with the default data,就按照intentUri的格式,The default data splicing into it,客户端通过IntentAvailable to the server with the default data.
intentUri格式:
intentUri:intent:#Intent;launchFlags=0x10000000;component=com.***.***/com.huawei.***. ActivityA;S.ext1=helloExt1;S.ext2=helloExt2;end
The default data can be usedS.key=value的方式拼接到intentUri
第四、Clean up application notification bar message
NotificationManager nm
=(NotificationManager)PushActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancelAll();
边栏推荐
- 华为IOT平台温度过高时自动关闭设备场景试用
- js学习进阶BOM部分(pink老师笔记)
- OpenMLDB + Jupyter Notebook: Quickly Build Machine Learning Applications
- 构建面向特征工程的数据生态 ——拥抱开源生态,OpenMLDB全面打通MLOps生态工具链
- Goldbach's conjecture and the ring of integers
- Promise.race学习(判断多个promise对象执行最快的一个)
- 论文解读TransFG: A Transformer Architecture for Fine-grained Recognition
- Tinker接入全流程---配置篇
- 经纬度求距离
- Use c language to implement tic-tac-toe chess (with source code, you can run it directly)
猜你喜欢

JVM调优整理

NUC980-开发环境搭建

Vscode remote connection server terminal zsh+Oh-my-zsh + Powerlevel10 + Autosuggestions + Autojump + Syntax-highlighting

精彩联动 | OpenMLDB Pulsar Connector原理和实操

STM32-中断优先级管理NVIC

NUC980-镜像烧录

关于接口响应内容的解码

实时特征计算平台架构方法论和基于 OpenMLDB 的实践

STM32学习笔记(白话文理解版)—USART通信接口

Event Preview | On April 23, a number of wonderful sharing sessions of OpenMLDB will come, which will live up to the good time of the weekend
随机推荐
STM32 基于固件库的工程模板的建立
He Kaiming's new work ViTDET: target detection field, subverting the concept of layered backbone
C语言中switch的嵌套
Tinker接入全流程---配置篇
Fourth Paradigm OpenMLDB optimization innovation paper was accepted by VLDB, the top international database association
STM32学习笔记(白话文理解版)—USART通信接口
OpenMLDB Pulsar Connector:高效打通实时数据到特征工程
Certificate of SearchGuard configuration
IIC and SPI
Day 86
开源之夏 2022 火热来袭 | 欢迎报名 OpenMLDB 社区项目~
Vscode远程连接服务器终端zsh+Oh-my-zsh + Powerlevel10 + Autosuggestions + Autojump + Syntax-highlighting
scanf函数在混合接受数据(%d和%c相连接)时候的方式
编译异常解决
Error: Flash Download failed - “Cortex-M4“-STM32F4
Simple mine sweeping in C language (with source code)
USB in NRZI to encode the data
使用ActiveReports制作第一张报表
红外线一认识
STM32学习笔记(白话文理解版)—小灯的点亮、闪烁、呼吸