Commit 8bb3ee7e authored by chengkun's avatar chengkun

加入华为推送代码文件

parent 56c998ca
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
android:protectionLevel="signature" /> android:protectionLevel="signature" />
<uses-permission android:name="com.shenghuoquan.business.permission.MIPUSH_RECEIVE" /> <uses-permission android:name="com.shenghuoquan.business.permission.MIPUSH_RECEIVE" />
<application> <application>
<meta-data
android:name="com.huawei.hms.client.channel.androidMarket"
android:value="false" />
<!--小米推送服务--> <!--小米推送服务-->
<receiver <receiver
android:name=".push.mipush.receiver.MiPushReceiver" android:name=".push.mipush.receiver.MiPushReceiver"
...@@ -86,5 +90,9 @@ ...@@ -86,5 +90,9 @@
</intent-filter> </intent-filter>
</service> <!--兼容Q版本--> </service> <!--兼容Q版本-->
</application> </application>
<queries>
<intent>
<action android:name="com.huawei.hms.core.aidlservice" />
</intent>
</queries>
</manifest> </manifest>
\ No newline at end of file
package com.yidian.shenghuoquan.bpush.push.huaweipush package com.yidian.shenghuoquan.bpush.push.huaweipush
import com.huawei.agconnect.config.AGConnectServicesConfig
import com.huawei.hms.aaid.HmsInstanceId
import com.yidian.shenghuoquan.bpush.app.BPushApplication
import com.yidian.shenghuoquan.bpush.push.PushPolicy import com.yidian.shenghuoquan.bpush.push.PushPolicy
class HuaWeiPushPolicy: PushPolicy() { class HuaWeiPushPolicy: PushPolicy() {
override fun initPushSdk() { override fun initPushSdk() {
TODO("Not yet implemented") val appId = AGConnectServicesConfig.fromContext(BPushApplication.context).getString("client/app_id")
val token = HmsInstanceId.getInstance(BPushApplication.context).getToken(appId, "HCM")
} }
override fun pubMessage(message: String) { override fun pubMessage(message: String) {
......
package com.yidian.shenghuoquan.bpush.push.huaweipush.service;
import android.text.TextUtils;
import android.util.Log;
import com.huawei.hms.push.HmsMessageService;
import com.huawei.hms.push.RemoteMessage;
import java.util.Arrays;
public class HuaweiPushGetDataService extends HmsMessageService {
private static final String TAG = "PushGetDataService";
// This method callback must be completed in 10 seconds. Otherwise, you need to start a new Job for callback processing.
// extends HmsMessageService super class
@Override
public void onNewToken(String token) {
Log.i(TAG, "received refresh token:" + token);
// send the token to your app server.
if (!TextUtils.isEmpty(token)) {
refreshedTokenToServer(token);
}
}
@Override
public void onMessageReceived(RemoteMessage message) {
Log.i(TAG, "onMessageReceived is called");
if (message == null) {
Log.e(TAG, "Received message entity is null!");
return;
}
Log.i(TAG, "getCollapseKey: " + message.getCollapseKey()
+ "\n getData: " + message.getData()
+ "\n getFrom: " + message.getFrom()
+ "\n getTo: " + message.getTo()
+ "\n getMessageId: " + message.getMessageId()
+ "\n getSendTime: " + message.getSentTime()
+ "\n getDataMap: " + message.getDataOfMap()
+ "\n getMessageType: " + message.getMessageType()
+ "\n getTtl: " + message.getTtl()
+ "\n getToken: " + message.getToken());
RemoteMessage.Notification notification = message.getNotification();
if (notification != null) {
Log.i(TAG, "\n getImageUrl: " + notification.getImageUrl()
+ "\n getTitle: " + notification.getTitle()
+ "\n getTitleLocalizationKey: " + notification.getTitleLocalizationKey()
+ "\n getTitleLocalizationArgs: " + Arrays.toString(notification.getTitleLocalizationArgs())
+ "\n getBody: " + notification.getBody()
+ "\n getBodyLocalizationKey: " + notification.getBodyLocalizationKey()
+ "\n getBodyLocalizationArgs: " + Arrays.toString(notification.getBodyLocalizationArgs())
+ "\n getIcon: " + notification.getIcon()
+ "\n getSound: " + notification.getSound()
+ "\n getTag: " + notification.getTag()
+ "\n getColor: " + notification.getColor()
+ "\n getClickAction: " + notification.getClickAction()
+ "\n getChannelId: " + notification.getChannelId()
+ "\n getLink: " + notification.getLink()
+ "\n getNotifyId: " + notification.getNotifyId());
}
Boolean judgeWhetherIn10s = false;
// If the messages are not processed in 10 seconds, the app needs to use WorkManager for processing.
if (judgeWhetherIn10s) {
startWorkManagerJob(message);
} else {
// Process message within 10s
processWithin10s(message);
}
}
private void startWorkManagerJob(RemoteMessage message) {
Log.d(TAG, "Start new job processing.");
}
private void processWithin10s(RemoteMessage message) {
Log.d(TAG, "Processing now.");
}
private void refreshedTokenToServer(String token) {
Log.i(TAG, "sending token to server. token:" + token);
}
}
...@@ -3,6 +3,7 @@ apply plugin: 'kotlin-android' ...@@ -3,6 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'yac-engine' apply plugin: 'yac-engine'
apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-parcelize' apply plugin: 'kotlin-parcelize'
apply plugin: 'com.huawei.agconnect'
android { android {
compileSdkVersion build_versions.compileSdkVersion compileSdkVersion build_versions.compileSdkVersion
......
...@@ -5,20 +5,19 @@ buildscript { ...@@ -5,20 +5,19 @@ buildscript {
addRepos(repositories) addRepos(repositories)
ext.kotlin_version = build_versions.kotlin_version ext.kotlin_version = build_versions.kotlin_version
repositories { repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url "https://jitpack.io" }
// 友盟 SDK maven仓库地址
maven { url 'https://repo1.maven.org/maven2/' }
// 新浪微博官方分享SDK
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
google() google()
mavenCentral() mavenCentral()
jcenter() jcenter()
// 配置HMS Core SDK的Maven仓地址。
maven {url 'https://developer.huawei.com/repo/'}
} }
dependencies { dependencies {
classpath deps.gradle.plugin classpath deps.gradle.plugin
classpath deps.kotlin.plugin classpath deps.kotlin.plugin
classpath deps.yac.engine classpath deps.yac.engine
// 增加agcp插件配置。
classpath 'com.huawei.agconnect:agcp:1.4.2.300'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
...@@ -27,18 +26,12 @@ buildscript { ...@@ -27,18 +26,12 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url "https://www.jitpack.io" }
// 友盟 SDK maven仓库地址
maven { url 'https://repo1.maven.org/maven2/' }
// 新浪微博官方分享SDK
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
maven { url "http://dailybuild2.yidian-inc.com:8088/repository/maven-public/" }
// ping++ maven仓库地址
maven { url "https://dl.bintray.com/pingxx/maven" }
google() google()
mavenCentral() mavenCentral()
jcenter() jcenter()
// 配置HMS Core SDK的Maven仓地址。
maven {url 'https://developer.huawei.com/repo/'}
} }
addRepos(repositories) addRepos(repositories)
} }
......
...@@ -140,7 +140,8 @@ ext.dependencies = [ ...@@ -140,7 +140,8 @@ ext.dependencies = [
// PictureSelector2.0 https://github.com/LuckSiege/PictureSelector // PictureSelector2.0 https://github.com/LuckSiege/PictureSelector
'io.github.lucksiege:pictureselector:v2.7.3-rc05', 'io.github.lucksiege:pictureselector:v2.7.3-rc05',
// Compressor https://github.com/zetbaitsu/Compressor // Compressor https://github.com/zetbaitsu/Compressor
'id.zelory:compressor:3.0.1' 'id.zelory:compressor:3.0.1',
'com.huawei.hms:push:5.3.0.304'
], ],
other : [ other : [
':CommonLib:BCommon' ':CommonLib:BCommon'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment