adjust / flutter_sdk

This is the Flutter SDK of
MIT License
58 stars 49 forks source link

Does not return android data when app is closed #76

Open Christyansoft opened 2 years ago

Christyansoft commented 2 years ago

I configured all android and ios steps in flutter and native, in ios the data is returned to flutter when app is closed or opened with invokeMethod. But on android it only returns when the app is open.

Flutter:

  static const platform = MethodChannel('flutter.native/deeplink');

  @override
  void initState() {
    super.initState();

    WidgetsBinding.instance?.addObserver(this);
    _initAdjust();

    platform.setMethodCallHandler((call) async {
      await Future.delayed(const Duration(seconds: 10));

      switch (call.method) {
        case 'getDeepLinkData':
          print('arguments: ${call.arguments.toString()}');
          print('method: ${call.method}');
          log('arguments: ${call.arguments}');
          //TODO -> DO SOMETHING
          break;
      }
    });

  }

  void _initAdjust() {
    final AdjustConfig adjustConfig =
    AdjustConfig('codeAdjust', AdjustEnvironment.production);
    adjustConfig.launchDeferredDeeplink = true;

    adjustConfig.logLevel = AdjustLogLevel.verbose;
    adjustConfig.deferredDeeplinkCallback = (String? uri) {
      print('[Adjust]: Received deferred deeplink: ' + uri.toString());
    };
    adjustConfig.attributionCallback = (AdjustAttribution attribution) {
      print('attribution callback');
    };
    Adjust.start(adjustConfig);
  }

Android:

  class MainActivity : FlutterActivity() {

    private val CHANNEL = "flutter.native/deeplink"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        GeneratedPluginRegistrant.registerWith(flutterEngine)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val intent = intent
        val data = intent.data
        AdjustSdk.appWillOpenUrl(data, this);
            Log.e("Url", data.toString())
            MethodChannel(
                flutterEngine?.dartExecutor?.binaryMessenger,
                CHANNEL
            ).invokeMethod("getDeepLinkData", data.toString())

    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        val data = intent.data
        AdjustSdk.appWillOpenUrl(data, this);
            Log.e("Url", data.toString())
            MethodChannel(
                flutterEngine?.dartExecutor?.binaryMessenger,
                CHANNEL
            ).invokeMethod("getDeepLinkData", data.toString())

    }

}
uerceg commented 2 years ago

Hi @Christyansoft

And sorry for delay on this one.

Hm, interesting. Lemme double check if I understood your issue first. You are trying to capture intent which has opened your Android app natively and pass it to Flutter layer, but it does not work in case of cold start (opening killed app) but it does work if your app is just in background?

If my understanding is correct, follow up question would be what doesn't work exactly - is your app not getting opened after a cold start at all or it does get opened, but passing deep link info to Flutter layer is not happening?