Skip to content

Commit

Permalink
UPDATE Push plugin to 5.1.1+301
Browse files Browse the repository at this point in the history
  • Loading branch information
fuatbakkal committed Apr 30, 2021
1 parent 2ef5854 commit 340a92c
Show file tree
Hide file tree
Showing 68 changed files with 2,101 additions and 1,282 deletions.
10 changes: 10 additions & 0 deletions flutter-hms-push/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 5.1.1+301
* Updated Push SDK to the latest version 5.1.1+301.
* Added Multi-Sender API.
* Bug fixes and improvements.
* **[Breaking Changes]**
* Migrated the plugin to Null-Safety.
* Folder structure updated, all library can be imported with a single line.
* Code constant renamed as ResultCodes.
* Push.deleteToken method's result will not be returned to the stream anymore, it can be obtained directly from the method.

## 5.0.2+304
* Updated HMSLogger.
* Changed lightSettings, vibrateConfig, titleLocalizationArgs and bodyLocalizationArgs fields of RemoteMessageNotification to type List\<dynamic> in order to support parsing for 3rd party integrations.
Expand Down
35 changes: 21 additions & 14 deletions flutter-hms-push/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,48 @@
<h1 align="center">Huawei Push Kit Flutter Plugin</h1>
</p>



<p align="center">
<a href="https://pub.dev/packages/huawei_gameservice"><img src="https://img.shields.io/pub/v/huawei_push?style=for-the-badge" alt="pub.dev version"></a>
</p>


----

HUAWEI Push Kit is a messaging service provided by Huawei. It establishes a messaging channel from the cloud to devices. By integrating Push Kit, you can send messages to your apps on users' devices in real time. This helps you maintain closer ties with users and increases user awareness and engagement with your apps.

This plugin enables communication between HUAWEI Push Kit SDK and Flutter platform. It exposes all functionality provided by HUAWEI Push Kit SDK.

[> Learn More](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/service-introduction-0000001050040060-V5)
[Learn More](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/service-introduction-0000001050040060-V5?ha_source=hms1)

## Installation

Please see [pub.dev](https://pub.dev/packages/huawei_push/install) and [AppGallery Connect Configuration](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/config-agc-0000001050178043).
Please see [pub.dev](https://pub.dev/packages/huawei_push/install) and [AppGallery Connect Configuration](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/config-agc-0000001050178043?ha_source=hms1).

## Documentation

- [Quick Start](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/basiccapabilities-0000001050417999)
- [Reference](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-References/overview-0000001057463088)
- [Quick Start](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/basiccapabilities-0000001050417999?ha_source=hms1)
- [Reference](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-References/overview-0000001057463088?ha_source=hms1)

### Additional Topics
- [Basic Capabilities](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/basiccapabilities-0000001050417999)
- [Topic-based Message Sending](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/topicbased-message-0000001050190681)
- [Receiving Data Messages](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/receiving-data-messages-at-killed-state-0000001058199547)
- [Deep Linking with Custom Intent URIs](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/deeplinking-custom-0000001055875857)
- [Obtaining Initial Messages](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/get-initial-notif-0000001056552970)
- [Listening to Message Tap Events](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/listen-notif-message-0000001057481400)
- [Sending Local Notification Messages](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/send-local-notif-0000001057760996)
- [Sending Uplink Messages](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/send-uplink-0000001057200983)
- [Basic Capabilities](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/basiccapabilities-0000001050417999?ha_source=hms1)
- [Topic-based Message Sending](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/topicbased-message-0000001050190681?ha_source=hms1)
- [Receiving Data Messages](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/receiving-data-messages-at-killed-state-0000001058199547?ha_source=hms1)
- [Deep Linking with Custom Intent URIs](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/deeplinking-custom-0000001055875857?ha_source=hms1)
- [Obtaining Initial Messages](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/get-initial-notif-0000001056552970?ha_source=hms1)
- [Listening to Message Tap Events](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/listen-notif-message-0000001057481400?ha_source=hms1)
- [Sending Local Notification Messages](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/send-local-notif-0000001057760996?ha_source=hms1)
- [Sending Uplink Messages](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/send-uplink-0000001057200983?ha_source=hms1)

## Questions or Issues

If you have questions about how to use HMS samples, try the following options:
- [Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services) is the best place for any programming questions. Be sure to tag your question with
**huawei-mobile-services**.
- [Github](https://github.com/HMS-Core/hms-flutter-plugin) is the official repository for these plugins, You can open an issue or submit your ideas.
- [Huawei Developer Forum](https://forums.developer.huawei.com/forumPortal/en/home?fid=0101187876626530001) HMS Core Module is great for general questions, or seeking recommendations and opinions.
- [Huawei Developer Docs](https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin) is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.
- [Huawei Developer Forum](https://forums.developer.huawei.com/forumPortal/en/home?fid=0101187876626530001?ha_source=hms1) HMS Core Module is great for general questions, or seeking recommendations and opinions.
- [Huawei Developer Docs](https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1) is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.

If you run into a bug in our samples, please submit an issue to the [GitHub repository](https://github.com/HMS-Core/hms-flutter-plugin).

Expand Down
3 changes: 2 additions & 1 deletion flutter-hms-push/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ android {
}

dependencies {
implementation 'com.huawei.hms:push:5.0.2.300'
implementation 'com.huawei.hms:push:5.1.1.301'
implementation 'com.huawei.hms:push-fcm:5.1.1.301'
implementation 'com.facebook.fresco:fresco:2.2.0'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
53 changes: 33 additions & 20 deletions flutter-hms-push/android/gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -66,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand All @@ -138,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -159,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
43 changes: 24 additions & 19 deletions flutter-hms-push/android/gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -35,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -45,28 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
import com.huawei.hms.flutter.push.utils.RemoteMessageUtils;
import com.huawei.hms.push.RemoteMessage;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
Expand All @@ -39,25 +35,30 @@
import io.flutter.view.FlutterNativeView;
import io.flutter.view.FlutterRunArguments;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

public class HeadlessPushPlugin implements MethodChannel.MethodCallHandler {
private static final String TAG = HeadlessPushPlugin.class.getSimpleName();

public final static String KEY_HANDLER = "push_background_message_handler";
public final static String KEY_CALLBACK = "push_background_message_callback";
public static final String KEY_HANDLER = "push_background_message_handler";

public static final String KEY_CALLBACK = "push_background_message_callback";

private static MethodChannel methodBackgroundChannel;
private static PluginRegistry.PluginRegistrantCallback pluginRegistrantCallback;

private MethodChannel methodBackgroundChannel;

private Context context;

private static FlutterNativeView flutterNativeView;
private FlutterNativeView flutterNativeView;

private static final AtomicBoolean SYNCHRONIZER = new AtomicBoolean(false);

public HeadlessPushPlugin(Context context) {
this.context = context;
if (flutterNativeView == null)
initFlutterNativeView();
initFlutterNativeView();

// Queue events while background isolate is starting
waitFlutterNativeView();
Expand Down Expand Up @@ -86,7 +87,6 @@ static void setPluginRegistrant(PluginRegistry.PluginRegistrantCallback callback
pluginRegistrantCallback = callback;
}


public void handleBackgroundMessage(Context context, RemoteMessage remoteMessage) {

SharedPreferences prefs = context.getSharedPreferences(Core.PREFERENCE_NAME, Context.MODE_PRIVATE);
Expand All @@ -106,24 +106,19 @@ private void initFlutterNativeView() {
FlutterMain.ensureInitializationComplete(context, null);

SharedPreferences prefs = context.getSharedPreferences(Core.PREFERENCE_NAME, Context.MODE_PRIVATE);
Long mCallbackHandle = prefs.getLong(KEY_HANDLER, -1);
long mCallbackHandle = prefs.getLong(KEY_HANDLER, -1);

FlutterCallbackInformation callbackInfo = FlutterCallbackInformation
.lookupCallbackInformation(mCallbackHandle);

if (callbackInfo == null) {
Log.e(TAG, "ERROR : failed to find callback");
return;
}
FlutterCallbackInformation callbackInfo = FlutterCallbackInformation.lookupCallbackInformation(mCallbackHandle);

flutterNativeView = new FlutterNativeView(context.getApplicationContext(), true);

// Create the Transmitter Channel
methodBackgroundChannel = new MethodChannel(flutterNativeView, Channel.BACKGROUND_MESSAGE_CHANNEL.id());
methodBackgroundChannel.setMethodCallHandler(this);

if (pluginRegistrantCallback == null)
if (pluginRegistrantCallback == null) {
return;
}

pluginRegistrantCallback.registerWith(flutterNativeView.getPluginRegistry());

Expand Down
Loading

0 comments on commit 340a92c

Please sign in to comment.