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

How do I debug if I am getting 'Error' ? #66

Closed rosdi closed 5 years ago

rosdi commented 5 years ago

Guys,

I am trying this plugin today, but I am at loss of trying to debug the error I am getting. How do I debug if there is any issue? All I am seeing is 'Error'.

Here is the code I am using (straight copy from sample)

window.plugins.intentShim.startActivity(
        {
            action: "window.plugins.intentShim.ACTION_VIEW", 
            url: 'http://www.google.co.uk',            
        },
        function() {},
        function(param) {
            alert('Failed to open URL via Android Intent: ' + JSON.stringify(param));
        }
    );

All I am getting is: Failed to open URL via Android Intent: "Error". I open adb logcat but not seeing anything there either.

Here is my config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="61" id="my.gov.mpaj.mympaj" ios-CFBundleVersion="61" version="0.0.4" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>MyApp</name>
    <content src="index.html" />
    <hook src="scripts/incrementBuildNum.js" type="after_build" />
    <preference name="AndroidPersistentFileLocation" value="Compatibility" />
    <preference name="AndroidLaunchMode" value="singleTask" />
    <access origin="https://api.tiles.mapbox.com" subdomains="true" />
    <access origin="https://*.gstatic.com" subdomains="true" />
    <access origin="https://*.google.com" subdomains="true" />
    <access origin="https://*.googleapis.com" subdomains="true" />
    <access origin="https://fonts.googleapis.com" subdomains="true" />
    <access launch-external="yes" origin="sspay-mbb-mpos://webPayment" />
    <access origin="cdvfile://*" />
    <allow-navigation href="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <icon src="res/icon.png" />
    <preference name="windows-target-version" value="10.0" />
    <vs:toolsetVersion xmlns:vs="http://schemas.microsoft.com/appx/2014/htmlapps">6.3.1</vs:toolsetVersion>
    <plugin name="cordova-plugin-geolocation" spec="https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git" />
    <plugin name="cordova-plugin-camera" spec="~1.2.0" />
    <plugin name="cordova.plugins.diagnostic" spec="~2.3.5" />
    <plugin name="cordova-plugin-device" spec="~1.1.1" />
    <plugin name="phonegap-plugin-barcodescanner" spec="https://github.com/wildabeast/BarcodeScanner.git" />
    <plugin name="cordova-plugin-whitelist" spec="~1.2.0" />
    <plugin name="cordova-plugin-appversion" spec="~1.0.0" />
    <plugin name="nirwan.cordova.plugin.printer" spec="https://github.com/pankajnirwan103/cordova-plugin-printer.git" />
    <plugin name="cordova-plugin-compat" spec="^1.2.0" />
    <plugin name="com-darryncampbell-cordova-plugin-intent" spec="https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent.git" />
    <engine name="browser" spec="^5.0.3" />
    <engine name="windows" spec="4.4.2" />
    <engine name="ios" spec="4.2.0" />
</widget>

And package.json...

{
  "name": "my.com.domain.myapp",
  "version": "0.0.4",
  "displayName": "MyApp",
  "cordova": {
    "platforms": [
      "browser",
      "windows",
      "ios"
    ],
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-geolocation": {},
      "cordova-plugin-camera": {},
      "cordova.plugins.diagnostic": {},
      "cordova-plugin-device": {},
      "phonegap-plugin-barcodescanner": {},
      "cordova-plugin-appversion": {},
      "nirwan.cordova.plugin.printer": {},
      "cordova-plugin-file-transfer": {},
      "cordova-plugin-compat": {},
      "com-darryncampbell-cordova-plugin-intent": {}
    }
  },
  "dependencies": {
    "cordova-android": "^6.3.0",
    "cordova-browser": "^5.0.3",
    "cordova-ios": "4.2.0",
    "cordova-plugin-appversion": "~1.0.0",
    "cordova-plugin-camera": "~1.2.0",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-device": "~1.1.1",
    "cordova-plugin-file-transfer": "~1.4.0",
    "cordova-plugin-geolocation": "https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git",
    "cordova-plugin-whitelist": "1",
    "cordova-windows": "4.4.2",
    "cordova.plugins.diagnostic": "~2.3.5",
    "nirwan.cordova.plugin.printer": "https://github.com/pankajnirwan103/cordova-plugin-printer.git",
    "phonegap-plugin-barcodescanner": "https://github.com/wildabeast/BarcodeScanner.git"
  }
}
darryncampbell commented 5 years ago

Hi, it looks like you need to remove the quotes around "window.plugins.intentShim.ACTION_VIEW". Please see the startActivityBrowser() method at https://github.com/darryncampbell/plugin-intent-api-exerciser/blob/master/www/js/index.js#L119 for an example.

rosdi commented 5 years ago

Lol... that's embarassing... it works but that's not my app actual use case... I need to open 3rd party app, here is a code sample from the app developer...

//java code sample from developer
Intent sendIntent = new Intent("mpay.apps.mpayconnect.REQUEST");
sendIntent.setType("text/plain");
sendIntent.putExtra("CALLBACK", "action.yourapp.CALLBACK");
startActivity(sendIntent);

How would I do this using this plugin? I asked the developer but they couldn't care less about cordova integration...

Btw, your plugin works with the standard actions ... feel free to close this if you think it is not appropriate to ask this question here... this is an excellent plugin.

darryncampbell commented 5 years ago

Something like the following should work based on your java code:

window.plugins.intentShim.startActivity(
        {
            action: 'mpay.apps.mpayconnect.REQUEST', 
            type: 'text/plain',
            extras: {
               'CALLBACK': 'action.yourapp.CALLBACK' //  the callback is a string?
            }
        },
        function() {},
        function(param) {
            alert('Failed to open URL via Android Intent: ' + JSON.stringify(param));
        }
    );
rosdi commented 5 years ago

Hmm..., that's actually my first try... before I changed it to window.plugins.intentShim.ACTION_VIEW to test whether the plugin is functioning... (which proven working because it is able to open the browser)..

When I use the code above all I got is Failed to open URL via Android Intent: "Error"

No exception or error log in adb logcat either. It would be helpful if there is stacktrace or exception thrown so that it is easier to see what the issue is.

darryncampbell commented 5 years ago

That could happen if no application has registered to receive mpay.apps.mpayconnect.REQUEST (https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent/blob/master/src/android/IntentShim.java#L417) but you might want to run the application in Android Studio and debug it to be sure what is going on - most of the other errors I can see have associated logcat messages

rosdi commented 5 years ago

Okay... I will find another way to debug this... I am suspicious about that action too...

I am actually a C# developer, and I want to avoid going to Android Studio and debug the plugin as I am really know nothing about Android development... setting up the development environment alone could take a day (if I am lucky)... I have even abandoned Java almost 10 years ago... ... but I probably have no choice I guess...

I will close this as this is not an issue with the plugin... I will update this thread if I found something that is related to the plugin... thanks for your time... really appreciate it...