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

Intent Handling - handleOnActivityResult is never called or crashes #1044

Closed
uzumakinaruto123 opened this issue Dec 11, 2018 · 10 comments
Closed

Comments

@uzumakinaruto123
Copy link

uzumakinaruto123 commented Dec 11, 2018

Trying to call a foreign activity and get result from it, but following error is thrown

E/JavaBinder(32387): !!! FAILED BINDER TRANSACTION !!!

java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 592196 bytes
   at  

Starting Activity and reading result as follows:

    @PluginMethod()
    public void startActivitiyForResultCustom(final PluginCall call){

        String b64Image = call.getString("foo");
        
        saveCall(call);

        Intent intent = new Intent();
        intent.putExtra("foo", foo);

        intent.setClassName("com.xyz.abc", "com.xyz.abc.Test");
        startActivityForResult(call, intent, 333);
    }

    @Override
    protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
        super.handleOnActivityResult(requestCode, resultCode, data);


        PluginCall savedCall = getSavedCall();

        if (savedCall == null) {
            return;
        }

        if (requestCode == 333) {
            PluginResult result = new PluginResult();
           result.put("foo", data.getStringExtra("foo"));
            savedCall.successCallback(result);
        }

    }

PS:- Foreign activity response is Stringified JSON with 1 or 2 keys and not image/bitmap data.

Foreign activity returns data as follows:

                Bundle extras = new Bundle();
                extras.putString("foo", "json string");
                Intent resultIntent = new Intent();
                resultIntent.putExtras(extras);
                finish();

Following works:

Starting activity with-
getActivity().startActivityForResult(intent, 333);

But this will return response in MainActivity

@jcesarmobile
Copy link
Member

Can you provide a sample app or the plugin you are using?

@uzumakinaruto123
Copy link
Author

Not the one I am working on! It's not a plugin! But, I will try reproducing this and provide a sample app.

As I said I am not doing much in App B, just doing the following which works if I try to get result in onActivityResult of MainActivity in Capacitor App.

                Bundle extras = new Bundle();
                extras.putString("foo", "{  \"key1\": \"value1\",  \"key2\": \"value2\",  \"key3\": \"value3\"}");
                Intent resultIntent = new Intent();
                resultIntent.putExtras(extras);
                finish();

@uzumakinaruto123
Copy link
Author

@jcesarmobile

The error occurs If I do saveCall(call) in PluginMethod

If call is not saved, following is logged in log cat

Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins 333

@jcesarmobile
Copy link
Member

If it’s not a plugin but manual changes on Capacitor classes you should handle your request code before capacitor tries to handle it

@uzumakinaruto123
Copy link
Author

If it’s not a plugin but manual changes on Capacitor classes you should handle your request code before capacitor tries to handle it

I am not sure how and where to do that! Any suggestion? or any way I can set Plugin callback from MainActivity? btw I am not changing any capacitor classes.

@alireza23
Copy link

Hi.
could You solve the problem?
I have the same problem and can,t get data back from native to Ionic

@uzumakinaruto123
Copy link
Author

@alireza23

For now, I created a Cordova Plugin for the same. But, it is specific to my project. So you will need to fork and update if you plan to use it.

https://github.com/uzumakinaruto123/cordova-plugin-native-intents

@jcesarmobile
Copy link
Member

Closing as it's still not clear to me what were you trying and you figured out how to do it in a different way.

@wch94
Copy link

wch94 commented Jun 12, 2019

Still getting "Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins 333" when using startActivityForResult. This issue should be reopened.

@jcesarmobile
Copy link
Member

Create a new issue with more information. It was closed because there was no enough information to investigate

@ionic-team ionic-team locked as resolved and limited conversation to collaborators Jun 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants