Skip to content

Commit

Permalink
add mindbox initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
umbrellait-timur-khismatullin committed Nov 5, 2022
1 parent 85da365 commit 40f10c6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.example.on_background_message
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import cloud.mindbox.mindbox_android.MindboxAndroidPlugin
import io.flutter.embedding.android.FlutterActivity
import com.example.test_plugin.TestPlugin

class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Handler(Looper.getMainLooper()).postDelayed({
TestPlugin.sendMessage("message from Android")
MindboxAndroidPlugin.pushClicked("link", "payload")
}, 3000)
}
}
15 changes: 13 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:mindbox/mindbox.dart';
import 'package:test_plugin/test_plugin.dart';

Future<void> handleBackGroundMessage(RemoteMessage message) async {}
Expand All @@ -11,13 +12,23 @@ void main() async {
// https://github.com/firebase/flutterfire/blob/master/packages/firebase_messaging/firebase_messaging/android/src/main/java/io/flutter/plugins/firebase/messaging/FlutterFirebaseMessagingBackgroundExecutor.java#L141
FirebaseMessaging.onBackgroundMessage(handleBackGroundMessage);

Mindbox.instance.init(
configuration: Configuration(
domain: 'invalid.configuration',
endpointIos: 'endpointIos',
endpointAndroid: 'endpointAndroid',
subscribeCustomerIfCreated: true,
),
);

// calling from Flutter
final platformVersion = await TestPlugin().getPlatformVersion();
print(platformVersion); // ok

// callback should be invoked from Android 3 seconds after the start application
TestPlugin().onMessageFromNative(callback: (message) {
print(message); // will never be called if a handler .onBackgroundMessage is set
Mindbox.instance.onPushClickReceived((link, payload) {
// will never be called if a handler .onBackgroundMessage is set
print('$link, $payload'); // I/flutter ( 1680): link, payload
});

runApp(const MyApp());
Expand Down
28 changes: 28 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
mindbox:
dependency: "direct main"
description:
path: "mindbox/mindbox"
relative: true
source: path
version: "2.1.5"
mindbox_android:
dependency: transitive
description:
path: "mindbox/mindbox_android"
relative: true
source: path
version: "2.1.5"
mindbox_ios:
dependency: transitive
description:
path: "mindbox/mindbox_ios"
relative: true
source: path
version: "2.1.5"
mindbox_platform_interface:
dependency: transitive
description:
path: "mindbox/mindbox_platform_interface"
relative: true
source: path
version: "2.1.5"
path:
dependency: transitive
description:
Expand Down

0 comments on commit 40f10c6

Please sign in to comment.