Closed caijiami closed 2 years ago
"react-native-aliyun-push": "^1.0.22", "react": "16.11.0", "react-native": "0.62.0",
@wonday @JadeZhu @haipengz @chenweigh Big man, please take a look
` buildscript { ext { buildToolsVersion = "29.0.0" minSdkVersion = 17 compileSdkVersion = 29 targetSdkVersion = 29 } repositories { google() jcenter() maven { url "https://jitpack.io" }
mavenCentral()
maven {
url 'https://dl.google.com/dl/android/maven2/'
name 'Google'
}
}
dependencies {
classpath("com.android.tools.build:gradle:3.5.2")
}
}
allprojects { repositories { mavenLocal() maven { url("$rootDir/../node_modules/react-native/android") } maven { url("$rootDir/../node_modules/jsc-android/dist") }
google()
jcenter()
maven {
url "http://maven.aliyun.com/nexus/content/repositories/releases/"
}
flatDir {
dirs project(':react-native-aliyun-push').file('libs')
}
maven {
url 'https://developer.huawei.com/repo/'
}
maven { url 'https://www.jitpack.io' }
maven { url 'https://maven.google.com' }
}
} `
` apply plugin: "com.android.application"
import com.android.build.OutputFile project.ext.react = [ enableHermes: false, // clean and rebuild if changing ] apply from: "../../node_modules/react-native/react.gradle" def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
android { compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.xz"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 419
versionName "4.1.9"
manifestPlaceholders = [
QQ_APPID: "1111846267",
]
multiDexEnabled true
missingDimensionStrategy 'react-native-camera', 'mlkit'
vectorDrawables.useSupportLibrary = true
ndk {
//选择要添加的对应cpu类型的.so库。为了兼容cpu,查看官网SDK的libs多添加几个
abiFilters 'arm64-v8a', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'x86', 'x86_64'
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
release {
storeFile file("./xggs.jks")
storePassword "mayiyi11"
keyAlias "mayiyi11"
keyPassword "mayiyi11"
}
debug {
storeFile file("./xggs.jks")
storePassword "mayiyi11"
keyAlias "mayiyi11"
keyPassword "mayiyi11"
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
packagingOptions {
pickFirst "lib/armeabi-v7a/libc++_shared.so"
pickFirst "lib/arm64-v8a/libc++_shared.so"
pickFirst "lib/x86/libc++_shared.so"
pickFirst "lib/x86_64/libc++_shared.so"
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies { compile project(':react-native-aliyun-push') implementation 'com.aliyun.ams:alicloud-android-push:3.1.9.1' compile 'com.aliyun.ams:huawei-push:2.6.3.305' compile 'com.aliyun.ams:huawei-push-base:2.6.3.305' compile 'com.aliyun.ams:third_vivopush:2.9.0.1'
implementation 'com.facebook.fresco:animated-gif:2.0.0'
implementation project(':react-native-image-picker')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' }
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
`
` <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xz.xggs" xmlns:tools="http://schemas.android.com/tools">
<!-- 阿里云推送相关权限 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- 接收推送主要权限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
android:banner="@drawable/tv_banner"
tools:replace="android:allowBackup"
android:networkSecurityConfig="@xml/network_security_config"
>
<activity
android:name=".MainActivity"
android:resizeableActivity="true"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="xggs"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<activity
android:name="com.xz.xggs.wxapi.WXEntryActivity"
android:label="@string/app_name"
android:exported="true"
android:taskAffinity="com.xz.xggs"
android:launchMode="singleTask"
/>
<activity
android:name="com.xz.xggs.wxapi.WXPayEntryActivity"
android:label="@string/app_name"
android:exported="true"
/>
<activity
android:name="com.xz.xggs.PopupPushActivity"
android:label="@string/app_name"
android:exported="true"
/>
<meta-data android:name="android.max_aspect" android:value="2.1" />
<uses-library android:name="org.apache.http.legacy" android:required="false" />
<meta-data android:name="com.alibaba.app.appkey" android:value="333533217"/> <!-- 你自己的阿里云- appKey -->
<meta-data android:name="com.alibaba.app.appsecret" android:value="b11a3a7b29e0494896085e2b31562b1a"/> <!-- 你自己的阿里云-appSecret -->
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="appid=101104522" />
<meta-data
android:name="com.vivo.push.api_key"
android:value="9673d19c31d273230b20e6fa" />
<meta-data
android:name="com.vivo.push.app_id"
android:value="103764327" />
</application>
`
` public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; }
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new BadgePackage());
return packages;
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; }
@Override public void onCreate() { super.onCreate(); SoLoader.init(this, / native exopackage / false); //下面是添加的代码 this.initCloudChannel(this); }
// 下面是添加的代码 /**
@param applicationContext */ private void initCloudChannel(final Context applicationContext) {
// 创建notificaiton channel this.createNotificationChannel(); PushServiceFactory.init(applicationContext); CloudPushService pushService = PushServiceFactory.getCloudPushService(); pushService.setNotificationSmallIcon(R.mipmap.ic_launcher_s);//设置通知栏小图标, 需要自行添加 pushService.register(applicationContext, "333533217", "b11a3a7b29e0494896085e2b31562b1a", new CommonCallback() { @Override public void onSuccess(String responnse) { // success } @Override public void onFailed(String code, String message) { // failed } }); // 注册方法会自动判断是否支持小米系统推送,如不支持会跳过注册。 MiPushRegister.register(applicationContext, "2882303761518199808", "5351818894808");
// 注册方法会自动判断是否支持华为系统推送,如不支持会跳过注册。 HuaWeiRegister.register(this);
// 接入FCM/GCM初始化推送 GcmRegister.register(applicationContext, "send_id", "application_id");
// OPPO通道注册 OppoRegister.register(applicationContext, "b48ae9b6ba974af99f60655d0de84105", "b01b28b24d1e454dabe3919bc8c0b4f6"); // appKey/appSecret在OPPO通道开发者平台获取
// VIVO通道注册 VivoRegister.register(applicationContext); }
private void createNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // 通知渠道的id String id = "1"; // 用户可以看到的通知渠道的名字. CharSequence name = "小新"; // 用户可以看到的通知渠道的描述 String description = "提示您收到了一条通知"; int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = new NotificationChannel(id, name, importance); // 配置通知渠道的属性 mChannel.setDescription(description); // 设置通知出现时的闪灯(如果 android 设备支持的话) mChannel.enableLights(true); mChannel.setLightColor(Color.RED); // 设置通知出现时的震动(如果 android 设备支持的话) mChannel.enableVibration(true); mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); //最后在notificationmanager中创建该通知渠道 mNotificationManager.createNotificationChannel(mChannel); } }
private static void initializeFlipper( Context context, ReactInstanceManager reactInstanceManager) { if (BuildConfig.DEBUG) { try { Class<?> aClass = Class.forName("com.keke.ReactNativeFlipper"); aClass .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) .invoke(null, context, reactInstanceManager); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } }
`
There are also auxiliary channel files added PopupPushActivity ` package com.xz.xggs;
import java.util.Map; import android.content.Intent; import android.os.Bundle;
import com.alibaba.sdk.android.push.AndroidPopupActivity; import com.facebook.react.bridge.ReactApplicationContext;
public class PopupPushActivity extends AndroidPopupActivity {
public static ReactApplicationContext context;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }
@Override protected void onSysNoticeOpened(String title, String summary, Map<String, String> extMap) { Intent intent=new Intent(); intent.setClass(PopupPushActivity.this, MainActivity.class); startActivity(intent); PopupPushActivity.this.finish(); } }
`
Please kindly help me to have a look, Huawei can not notify after killing the app, only open the app can receive the notification
refer to https://help.aliyun.com/document_detail/190012.htm?spm=a2c4g.11186623.0.0.65875b78F7Nmnu#topic-1997157
我已经按文档做了每个步骤,只有小米可以,杀死app后通知
refer to
https://help.aliyun.com/document_detail/190012.htm?spm=a2c4g.11186623.0.0.65875b78F7Nmnu#topic-1997157
我已经按文档做了每个步骤,只有小米可以,杀死app后通知
之前用的极光都可以
The secondary channels are all configured, but no push can be received after the app is killed