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 136 forks source link

Error using the plugin with ionic capacitor #64

Closed redwolf2 closed 5 years ago

redwolf2 commented 5 years ago
D/Cordova Intents Shim: Action: registerBroadcastReceiver
E/PluginManager: Uncaught exception from plugin
    java.lang.ClassCastException: de.test.example.MainActivity cannot be cast to org.apache.cordova.CordovaActivity
        at com.darryncampbell.cordova.plugin.intent.IntentShim.execute(IntentShim.java:118)
        at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
        at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
        at com.getcapacitor.MessageHandler.callCordovaPluginMethod(MessageHandler.java:73)
        at com.getcapacitor.MessageHandler.postMessage(MessageHandler.java:46)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:323)
        at android.os.Looper.loop(Looper.java:136)
        at android.os.HandlerThread.run(HandlerThread.java:61)

It works if I replace all ((CordovaActivity)this.cordova.getActivity()) with this.cordova.getActivity()

Created a pull request here: https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent/pull/65

If you want to test it yourself, with an already existing project, start here: https://capacitor.ionicframework.com/docs/getting-started/with-ionic

redwolf2 commented 5 years ago

Merged

redwolf2 commented 5 years ago

Can you please release a new binary. Version 1.1.2 is the latest version, that does not have the fix ATM.

darryncampbell commented 5 years ago

Sorry, it completely slipped my mind. 1.1.3 has now been posted to npm: https://www.npmjs.com/package/com-darryncampbell-cordova-plugin-intent

nachomozo commented 5 years ago

I get the same error with capacitor and I have 1.1.7 version. In startActivity instead of registerBroadcastReceiver.

2019-07-14 22:51:19.696 7882-7952/io.ionic.starter D/Cordova Intents Shim: Action: startActivity
2019-07-14 22:51:19.698 7882-7952/io.ionic.starter E/PluginManager: Uncaught exception from plugin
    java.lang.ClassCastException: io.ionic.starter.MainActivity cannot be cast to org.apache.cordova.CordovaActivity
        at com.darryncampbell.cordova.plugin.intent.IntentShim.startActivity(IntentShim.java:420)
        at com.darryncampbell.cordova.plugin.intent.IntentShim.execute(IntentShim.java:83)
        at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
        at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
        at com.getcapacitor.MessageHandler.callCordovaPluginMethod(MessageHandler.java:73)
        at com.getcapacitor.MessageHandler.postMessage(MessageHandler.java:46)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:323)
        at android.os.Looper.loop(Looper.java:136)
        at android.os.HandlerThread.run(HandlerThread.java:61)
nachomozo commented 5 years ago

I created a pull request: #77

This fixes the error for me using Capacitor, but I cannot test it using Cordova.

Thank you :)