Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not return android data when app is closed #76

Open
Christyansoft opened this issue Mar 31, 2022 · 1 comment
Open

Does not return android data when app is closed #76

Christyansoft opened this issue Mar 31, 2022 · 1 comment

Comments

@Christyansoft
Copy link

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
Copy link
Contributor

uerceg commented Jun 9, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants