当前位置:网站首页>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();
边栏推荐
猜你喜欢
关于接口响应内容的解码
使用ActiveReports制作第一张报表
USB中用NRZI来编码数据
华为IOT设备消息上报和消息下发验证
127.0.0.1 connection refused
STM32学习笔记(白话文理解版)—USART通信接口
Vscode远程连接服务器终端zsh+Oh-my-zsh + Powerlevel10 + Autosuggestions + Autojump + Syntax-highlighting
The whole process of Tinker access --- Compilation
gerrit 配置SSH Key和账号、邮箱信息
构建面向特征工程的数据生态 ——拥抱开源生态,OpenMLDB全面打通MLOps生态工具链
随机推荐
贡献者任务第三期精彩来袭
Tinker的自我介绍
ARM 汇编指令 ADR 与 LDR 使用
vim 编辑解决中文乱码问题
The third phase of the contributor task is wonderful
Open Source Machine Learning Database OpenMLDB Contributor Program Fully Launched
Error: Flash Download failed - “Cortex-M4“-STM32F4
张小龙的微信公开课(2019年)
Building a data ecology for feature engineering - Embrace the open source ecology, OpenMLDB fully opens up the MLOps ecological tool chain
精彩联动 | OpenMLDB Pulsar Connector原理和实操
经纬度求距离
谨此留个纪念
STM32学习总结(一)——时钟RCC
C language implementation guess Numbers (with source code, can be directly run)
2021-09-11 C language variables and memory allocation
如何快速转行做产品经理
SearchGuard证书配置
aPaaS和iPaaS的区别
ActiveReports报表分类之页面报表
活动预告 | 4月23日,多场OpenMLDB精彩分享来袭,不负周末好时光