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

await ReceiveIntent.setResult Not working #2

Closed
sikandernoori opened this issue Jul 8, 2021 · 12 comments
Closed

await ReceiveIntent.setResult Not working #2

sikandernoori opened this issue Jul 8, 2021 · 12 comments
Assignees

Comments

@sikandernoori
Copy link

sikandernoori commented Jul 8, 2021

Hello @daadu

I am performing Intent using below Code which works fine.

onPressed: () => android_intent.Intent()
                   ..setAction("com.packagename.MYINTENT")
                  ..startActivityForResult().then(
                    (data) {
                      print("mydata " + data.toString());
                      setState(() {
                        _scanBarcode = data.toString();
                      });
                    },
                    onError: (e) => print("error occured: " + e.toString()),
                  ),

The intent Open the App and after performing the Functionality I am calling your Plugin like below:

Future<void> _setActivityResult() async {
    await ReceiveIntent.setResult(999, data: {"sum": 123}, shouldFinish: true);
  }

After this function App Closes and I am back to parent App from where I Launched the Activity but in result the data is not being showed.
Am i missing any additional parameter ?

@daadu
Copy link
Owner

daadu commented Jul 9, 2021

@sikandernoori The code snippet looks ok to me.

Can you share logs? Maybe there could be some hint.

Also if you could go through plugin code, to debug it would really help.

@daadu daadu added the bug Something isn't working label Jul 9, 2021
@daadu daadu assigned daadu and sikandernoori and unassigned daadu Jul 9, 2021
@daadu daadu removed the bug Something isn't working label Jul 9, 2021
@daadu
Copy link
Owner

daadu commented Jul 9, 2021

Can you confirm that the "data" in the code is what you are calling it with.

There are restriction to what "type" of data could be send, It has to be one of the following -> String, int, bool, double or another Map.

Check this function to know more -

fun jsonToBundle(json: JSONObject): Bundle {

@sikandernoori
Copy link
Author

sikandernoori commented Jul 9, 2021

I think maybe your Plugin is working Okay.

Because I am using Two Plugins.

1- https://pub.dev/packages/intent. -> To StartIntent Activity using below Code.

onPressed: () => android_intent.Intent()
                   ..setAction("com.packagename.MYINTENT")
                  ..startActivityForResult().then(
                    (data) {
                      print("mydata " + data.toString());
                      setState(() {
                        _scanBarcode = data.toString();
                      });
                    },
                    onError: (e) => print("error occured: " + e.toString()),
                  ),

This Functions open the the Intent App and in that App I am calling your plugin to send result back and finish Activity using below Code

Future<void> _setActivityResult() async {
    await ReceiveIntent.setResult(999, data: {"sum": 123}, shouldFinish: true);
  }

Now Your Plugin Does Close the App and I get back to the Main App, but in Main App the data is not received -> {"sum" : "123"} should be received but I am getting Null.

@daadu
Copy link
Owner

daadu commented Jul 9, 2021

Which plugin are you using to call the "AcitivtyForResult" ?

@daadu
Copy link
Owner

daadu commented Jul 9, 2021

receive_intent puts the data in "Intent.bundle", maybe that plugin maybe expecting something else in callback?

@sikandernoori
Copy link
Author

Which plugin are you using to call the "AcitivtyForResult" ?

https://pub.dev/packages/intent

@daadu
Copy link
Owner

daadu commented Jul 9, 2021

The code (of intent plugin) indicates, that it is looking for "Intent.data" with some specific type - filepath, URL, etc.

Check following:
https://github.com/itzmeanjan/intent/blob/7ebae1dac32058dcefa622f52ee4da354146769a/android/src/main/kotlin/io/github/itzmeanjan/intent/IntentPlugin.kt#L39-L78

While our plugin puts the data in Intent.bundle, that is why you are not getting the data in the callback.

@sikandernoori
Copy link
Author

Can you Suggest an alternative to get this working ?

@daadu
Copy link
Owner

daadu commented Jul 9, 2021

Opened a new issue regarding it #3. Feel free to file PR for it.

@daadu
Copy link
Owner

daadu commented Jul 9, 2021

As of now you can wait or code #3 your self.

OR

Use linker plugin, I haven't used myself, but quick look at their code - suggests that in callback you will get "full intent", you should find the "data" in that "result.extra"

@daadu
Copy link
Owner

daadu commented Jul 9, 2021

Also, I am incorrect above, we put "data" in Intent.extras (there is nothing like Intent.bundle!!)

@sikandernoori
Copy link
Author

Thank You @daadu.

It seems like the best forward is to write my own plugin for StartActivityForResult after that maybe I can use your Plugin Intent for closing Activity.

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