当前位置:网站首页>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();
边栏推荐
猜你喜欢
随机推荐
STM32学习总结(二)——GPIO
MSP430学习总结(二)——GPIO
MSP430学习总结——时钟UCS
微文案也能提升用户体验
STM32F4-正点原子探索者-SYSTEM文件夹下的delay.c文件内延时函数详解
何凯明新作ViTDET:目标检测领域,颠覆分层backbone理念
STM32学习总结(一)——时钟RCC
SearchGuard配置
EMQX企业版试用笔记
ASP.NET MVC 4中实现action的事务功能
Node 踩坑之80端口被占用
js学习进阶BOM部分(pink老师笔记)
CKEditor富文本编辑器工具栏自定义笔记
红外线应用-红外遥控
产品如何拟定优化方案?
厂商推送平台-华为接入
IIC 和 SPI
产品经理的基础知识
使用adb命令管理应用
端口的作用