darryncampbell / darryncampbell-cordova-plugin-intent

General purpose intent shim layer for cordova appliations on Android. Handles various techniques for sending and receiving intents.
MIT License
86 stars 130 forks source link

Added the ability to add class instances to intents #135

Closed jdgjsag67251 closed 2 years ago

jdgjsag67251 commented 2 years ago

Use case

We would like to call an intent of a third party app that requires that we provide a BigDecimal in the Intent. Since we are not able to transfer Java objects to JS (and back), we must have some solution in this library. The solution I came up with was to handle objects that contain the $class key in a special way, allowing the lib to create the object in Java with specific parameters.

Example

const amount = 2;

window.plugins.intentShim.startActivityForResult({
  action: '...',
  extras: {
    'bigDecimal': { $class: 'java.math.BigDecimal', arguments: [amount.toFixed(2)] },
  },
}, console.log, console.error);
darryncampbell commented 2 years ago

All looks good, thank you for your contribution. It took longer to test than I expected because some of my tests were affected by package visibility changes in SDK30

darryncampbell commented 2 years ago

Give me a day or two to look over https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent/pull/136 then I'll update the version on npm with both changes, thanks!

darryncampbell commented 2 years ago

Posted to npm as 2.2.0