0

I've implemented MC Cordova Plugin (https://github.com/salesforce-marketingcloud/MC-Cordova-Plugin) for push notification through Marketing Cloud for hybrid mobile app, but encountering problems.

On Android platform, Any functions I called from the app didn't have callback return; in iOS platform I get the callback return for isPushEnabled function, but for enablePush it is not having the callback return, and I can't get the system token when I called MCCordovaPlugin.getSystemToken .

Previously similar question here : salesforce-marketingcloud android push no

I've used Java 1.8, Cordova 7.0.0, Android Cordova v.6.3.0 but there's still not callback return (and also no error).

MC Cordova Plugin version : 1.0.2

Snippet Code :

var $j = jQuery.noConflict();
var logToConsole = cordova.require("com.salesforce.util.logger").logToConsole;
$j('#link_fetch_device_contacts').click(function() {
                                       logToConsole("link_fetch_device_contacts clicked");
                                       var options      = new ContactFindOptions();
                                       options.filter   = ""; // empty search string returns all contacts
                                       options.multiple = true;
                                       options.hasPhoneNumber = true;
                                       var fields       = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
                                       navigator.contacts.find(fields, onSuccessDevice, onErrorDevice, options);

                                        console.log("MCCordovaPlug :");
                                        console.log(MCCordovaPlugin);

                                        document.addEventListener("deviceready",function(){
                                            console.log("deviceready");
                                            MCCordovaPlugin.isPushEnabled(function(success){
                                                console.log("is Push Enabled Success");
                                                console.log(success);
                                                }, function(error){
                                                console.log("is Push Enabled Error");
                                                console.log(error);
                                            });
                                        }, false);

                                       });

Log:

03-01 12:10:10.949 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(38)] "jslog: link_fetch_device_contacts clicked", source: file:///android_asset/www/plugins/com.salesforce/www/com.salesforce.util.logger.js (38)
03-01 12:10:10.958 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(15)] "MCCordovaPlug :", source: file:///android_asset/www/inline.js (15)
03-01 12:10:10.960 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(16)] "[object Object]", source: file:///android_asset/www/inline.js (16)
03-01 12:10:10.960 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(19)] "deviceready", source: file:///android_asset/www/inline.js (19)
03-01 12:10:10.960 2174-2682/com.sfapp.contactexplorer V/~#MCSdkCordovaPlugin: EXECUTING ACTION: isPushEnabled
03-01 12:10:10.965 2174-2682/com.sfapp.contactexplorer V/handleIsPushEnabled: org.apache.cordova.CallbackContext@4b990d2
03-01 12:10:10.971 2174-2682/com.sfapp.contactexplorer V/tryHandleIsPushEnabled: org.apache.cordova.CallbackContext@4b990d2
03-01 12:10:11.148 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(38)] "jslog: onSuccessDevice: received 119 contacts", source: file:///android_asset/www/plugins/com.salesforce/www/com.salesforce.util.logger.js (38)

Edited : I have try to put Log.v in MCCordovaPlugin.java , but seems it stucked in this function :

private boolean handleIsPushEnabled(final CallbackContext callbackContext) {
        Log.v("handleIsPushEnabled",callbackContext.toString());
        try {
            Log.v("tryHandleIsPushEnabled",callbackContext.toString());
            MarketingCloudSdk.requestSdk(new MarketingCloudSdk.WhenReadyListener() {
                @Override
                public void ready(MarketingCloudSdk marketingCloudSdk) {
                    Log.v("handleIsPushEnabledSuccess",callbackContext.getCallbackId());
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, marketingCloudSdk.getPushMessageManager().isPushEnabled()));
                }
            });
        } catch (Exception e) {
            Log.v("handleIsPushEnabledError",e);
            return caughtException(callbackContext, e);
        }
        return true;
    }

There is no "handleIsPushEnabledSuccess" or "handleIsPushEnabledError" printed on logcat; directly return true.

EDITED : On Android it already works (Thanks guys for answering my question!) Now the next question is : How can I retrieve the contact key that is automatically generated from MC when we call enablePush ?

Please help about this issue.. Thanks!

Best Regards

7
  • Can you verify your dir structure for the install. Java/com.salesforce.marketingcloud.cordovaplugin dir and that the plugin has 3 files, MainActivity, MCCordovaPlugin, MCCordovaPluginApplication? If so are you still not able to debug to anything in the onCreate() method in the MCCordovaPluginApplication?
    – Bill Mote
    Commented Feb 27, 2018 at 13:03
  • What version of the plugin are you using? Please enable logging in the plugin and provide the output.
    – Bill Mote
    Commented Feb 27, 2018 at 13:41
  • Hi @BillMote, from what I see in Android Studio, the file in android/java/com/salesforce.marketingcloud.cordovaplugin are MCCordovaPlugin.java and MCCordovaPluginApplication.java, while MainActivity,java is in android/java/com/package.name folder. I tried to debug for enablePush and the result shown was only until function in MCCordovaPlugin.java : /com.pkg.name V/~#MCSdkCordovaPlugin: EXECUTING ACTION: enablePush /com.pkg.name V/~#MCSdkCordovaPlugin: EXECUTING ACTION: isPushEnabled after that directly jump to other plugin execution /com.pkg.name V/PushPlugin: execute: action=init
    – Lyon Stark
    Commented Feb 28, 2018 at 2:19
  • @BillMote I use the latest plugin, install it by => cordova plugin add github.com/salesforce-marketingcloud/… APPID={MC_APP_ID} --variable ACCESSTOKEN={MC_ACCESS_TOKEN} --variable GCMSENDERID={GCM_SENDER_ID} --variable MCANALYTICS="enabled" --variable CHANNELNAME={MC_CHANNEL_NAME} --nosave --nofetch
    – Lyon Stark
    Commented Feb 28, 2018 at 2:22
  • Please update your question with version info and log output.
    – Bill Mote
    Commented Feb 28, 2018 at 4:05

2 Answers 2

1

As you linked my thread I will give you few things I've learned from my issues with Android.

1)Make sure you have import {package}.R; in MCCordovaPluginApplication.java file. (otherwise it wont compile)

2) Make sure android hook fired after you execute cordova prepare . Look inside your AndroidManifest file and see if you have entry

android:name="com.salesforce.marketingcloud.cordovaplugin.MCCordovaPlugingApplication.java"

if above entry is missing then hook didn't fire and u need to either fix plugin or add it manually ....

it should look something like following .<application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true" android:name="com.salesforce.marketingcloud.cordovaplugin.MCCordovaPluginApplication">

7
  • From reading your answear above looks like you experiencing issue number 2 hook not been fired.
    – Serge Tk
    Commented Mar 1, 2018 at 9:54
  • Hi Serge Tk, thanks for the answer, really appreciate it. Currently I also use Salesforce Mobile SDK Plugin (github.com/forcedotcom/SalesforceMobileSDK-CordovaPlugin) v.5.3.0. So, the application format is like this: <application android:hardwareAccelerated="true" android:icon="@drawable/sf__icon" android:label="@string/app_name" android:manageSpaceActivity="com.salesforce.androidsdk.ui.ManageSpaceActivity" android:name="com.salesforce.androidsdk.phonegap.app.HybridApp" android:supportsRtl="true"> Can we use both Mobile SDK SF lugin & MCCordovaPlugin at the same time?
    – Lyon Stark
    Commented Mar 1, 2018 at 14:20
  • Knowing the application in AndroidManifest.xml is only one..
    – Lyon Stark
    Commented Mar 1, 2018 at 14:21
  • Hello. Your current issue is same I face which is another plugin using android: name...... In my case, I use IBM's mobileFirst platform plugin. But solution is fairly simple you simply overwrite one of the files to extend the other ... public class MFPApplication extends Application { so I've changed that to be public class MFPApplication extends MCCordovaPluginApplication { .
    – Serge Tk
    Commented Mar 1, 2018 at 19:48
  • Also this link was good explanation on how to deal with multiple plugins which extend Applications . [multiple applications] stackoverflow.com/questions/19001644/…
    – Serge Tk
    Commented Mar 1, 2018 at 20:19
0

There are a couple things to consider here: 1. You might need to make sure you add in the android:name="com.salesforce.marketingcloud.cordovaplugin.MCCordovaPluginApplication" into the manifest file.

If you are having issues doing this since hooks seem to be broken at this point, you can add via shell overwriting your manifest file. Just be careful about any application-specific values that you may already have in there in your version. Here is a shell script something like this in order to help you. Or just manually edit the values yourself.

cp -a ./platforms/ ./platformsBck rm -R ./platforms/ cordova plugin add ../MarketingCloudSdk-Cordova-Plugin —variable APPID={YOUR_APP_ID} —variable ACCESSTOKEN={YOUR_ACCESS_TOKEN} —variable GCMSENDERID={YOUR_GCM_SENDER_ID} —variable MCANALYTICS={enabled|disable} —variable CHANNELNAME={YOUR_CHANNEL_NAME} —nosave —nofetch cordova prepare cp -a ./platformsBck/android/ ./platforms/android/ rm -R ./platformsBck/

  1. But, in your case it seems like you already are setting the android:name value in your manifest to something else. It also seems you can only set this value once. If you already have this set from some other Application plugin path, then you can take our content from our public void onCreate() {} in our plugin MCCordovaPluginApplication.java and add it to your existing one in your Application class.

I hope this helps.

5
  • 1
    Thanks for the input, Tom! Will try it for sure. Currently it has worked by change the <application> android name to MCCordovaPluginApplication 😊
    – Lyon Stark
    Commented Mar 2, 2018 at 4:57
  • 1
    Awesome news! Please keep us updated.
    – Tom Brooks
    Commented Mar 2, 2018 at 11:59
  • hi Tom, once we enablePush to MC, then contact key automatically made in the MC right.. How can we retrieve the contact key from MC using this plugin?
    – Lyon Stark
    Commented Mar 5, 2018 at 9:44
  • Hello Lyon, I'm glad you're making progress here. According to ReadMe github.com/salesforce-marketingcloud/MC-Cordova-Plugin you need to explicitly set the Contact Key using: MCCordovaPlugin.setContactKey(successCallback, errorCallback, contactKey); and to get the contact key you would query by using: MCCordovaPlugin.getContactKey(successCallback, errorCallback); Any modified values are sent to the MC when the application moves from foreground to background making a registration call and within a few minutes for the MC to pick up the value. Let me know if that helps!
    – Tom Brooks
    Commented Mar 6, 2018 at 12:12
  • hi Tom, thanks for the information! Now I have set and get the contact key successfully :) Do you know where can I apply some functions when I tap on push notification received (app run in background)? e.g. redirect to certain pages.. Because I don't find anywhere from the documentation.. Thanks a lot for your help, Tom.
    – Lyon Stark
    Commented Mar 9, 2018 at 5:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .