wonday / react-native-aliyun-push

A react native wrapper for aliyun push SDK
MIT License
218 stars 64 forks source link

When you close the APP, you don't receive notifications. When you open the APP, you receive notifications #155

Closed caijiami closed 2 years ago

caijiami commented 2 years ago

The secondary channels are all configured, but no push can be received after the app is killed

caijiami commented 2 years ago

"react-native-aliyun-push": "^1.0.22", "react": "16.11.0", "react-native": "0.62.0",

caijiami commented 2 years ago

@wonday @JadeZhu @haipengz @chenweigh Big man, please take a look

caijiami commented 2 years ago

` 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' }
}

} `

caijiami commented 2 years ago

` 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)

`

caijiami commented 2 years ago

` <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>

`

caijiami commented 2 years ago

` 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); }

// 下面是添加的代码 /**

`

caijiami commented 2 years ago

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(); } }

`

caijiami commented 2 years ago

Please kindly help me to have a look, Huawei can not notify after killing the app, only open the app can receive the notification

BridgeEast commented 2 years ago

refer to https://help.aliyun.com/document_detail/190012.htm?spm=a2c4g.11186623.0.0.65875b78F7Nmnu#topic-1997157

caijiami commented 2 years ago

我已经按文档做了每个步骤,只有小米可以,杀死app后通知

refer to https://help.aliyun.com/document_detail/190012.htm?spm=a2c4g.11186623.0.0.65875b78F7Nmnu#topic-1997157

我已经按文档做了每个步骤,只有小米可以,杀死app后通知

caijiami commented 2 years ago

之前用的极光都可以