Software Archive
Read-only legacy content
17061 Discussions

Cordova WebIntent Plugin not working

Anjali_P_
Beginner
2,200 Views

Hii..

I have used the plugin from the following link : https://github.com/Initsogar/cordova-webintent.git

Set the minimum android API level as 16 and Maximum target API level as 21 in the build settings.

After, building the apk by using cordova CLI.  

The code I used to start an activity is shown below :

window.cordova.plugins.webintent.startActivity
            ({
                  action: window.plugins.webintent.ACTION_VIEW,
                  url: "file:///storage/emulated/0/Download/anjali/test.apk",
                  type: 'application/vnd.android.package-archive'
                },
                function() {alert("inside success webintent");},
                function(){ alert('Failed to open URL via Android Intent');}
            );

This mentioned above function will be called only after device ready event.

An exception is thrown for this plugin as : TypeError : Cannot read property 'webintent' of undefined.

Reply as soon as possible.

0 Kudos
7 Replies
PaulF_IntelCorp
Employee
2,200 Views

I suspect that plugin was not added to your app, if you are using PhoneGap Build you can check their build log to see if that is the case, if using Cordova CLI you should have seen an error on the command-line when you attempted to add the plugin using CLI. When I click the link you provided it goes nowhere. See this Ionics forum post > https://forum.ionicframework.com/t/https-github-com-initsogar-cordova-webintent-is-404/85429 < for more help.

0 Kudos
Anjali_P_
Beginner
2,200 Views

From the link you have shared I used the following plugin : https://github.com/marcelchastain/cordova-webintent

But, then also same exception is thrown.

I checked in the simulator, atleast there is no exception thrown.

But, after building the apk and installing in the phone, an exception is thrown as (TypeError : Cannot read property 'webintent' of undefined.).

Also, I tried to extract the apk built by using Cordova CLI by using online Java Decomplier tools.

With the extracted components, all the plugins folder are there, except the web intent plugin folder.

Need help as soon as possible.

0 Kudos
PaulF_IntelCorp
Employee
2,200 Views

Please review the plugin implementation > https://github.com/marcelchastain/cordova-webintent/blob/master/www/webintent.js < because the object reference you are making appears to be wrong.

You do not need to decompile anything to figure out if the plugin was added, just unzip the APK file and you'll be able to quickly see if the plugin is present. For example, after building a test project that included that plugin, and unzipping the APK file that I got from PhoneGap Build, I see this when I look at the unzipped folder (I've highlighted the plugin of interest):

Screen Shot 2017-07-25 at 09.48.02 .png

Or, build a debug version of the app, install it and run it on your device, and attach your device to your USB port to test at the JavaScript console. I took the app I built above that includes that plugin and I can see that the plugin was included by doing the following at the JavaScript console when I'm using remote CDT to debug the app:

> console.log(JSON.stringify(cordova.require('cordova/plugin_list').metadata, null, 1))
{
 "cordova-plugin-device": "1.1.2",
 "cordova-plugin-splashscreen": "3.2.2",
 "cordova-plugin-screen-orientation": "1.4.2",
 "cordova-plugin-dialogs": "1.2.1",
 "phonegap-plugin-barcodescanner": "4.1.0",
 "cordova-plugin-battery-status": "1.1.2",
 "com.borismus.webintent": "1.0.3",
 "cordova-plugin-whitelist": "1.2.2"
}

It's the second-to-last plugin listed. Which I added to my project using this GitHub repo URL > https://github.com/marcelchastain/cordova-webintent < and then built using PhoneGap Build using the ZIP file that I exported from the XDK.

From that same debug console, you can see that the plugin is present and available, below is a screenshot from the remote CDT console and my test above, as well as an expansion of the window.webintent object created by that plugin:

Screen Shot 2017-07-25 at 09.51.34 .png

Also, double-check the process you are using to add the plugin to your project. You can easily confirm that it is in the project by simply looking at the plugin management tool:

Screen Shot 2017-07-25 at 09.54.12 .png

 

0 Kudos
Anjali_P_
Beginner
2,200 Views

As you have mentioned above, I create a new project and attached the third party webintent plugin.In the intel xdk, after attaching the plugin, in the project tab under plugin management , the plugin has been attached (Shown below is the screenshot)

refer1.png

I am using Cordova CLI to build the apk files.

The following are the screenshot of the cordova CLI :

refer2.png

refer3.png

After the unzipping the apk file, all the plugin files folder are there except :  com.borismus.webintent

The following is the code for the index.html:

<!DOCTYPE html>
<html>
<head>
    <title>Blank Cordova Mobile App Template</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no">
    <style>
        @-ms-viewport { width: 100vw ; min-zoom: 100% ; zoom: 100% ; }          @viewport { width: 100vw ; min-zoom: 100% zoom: 100% ; }
        @-ms-viewport { user-zoom: fixed ; min-zoom: 100% ; }                   @viewport { user-zoom: fixed ; min-zoom: 100% ; }
        /*@-ms-viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; }   @viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; }*/
    </style>
    <link rel="stylesheet" href="css/app.css"/>
     <script src="cordova.js"></script>
    <script src="js/app.js"></script>
    <script src="js/init-app.js"></script>
    <script src="xdk/init-dev.js"></script>
</head>
<body>
    <div>TEST WEBINTENT SAMPLE</div><br><br>
    <center><input type='button' value ='click' id='clickBtn' onclick ='btnClick();'/></center>
</body>
    <script>
        function $(id){ return document.getElementById(id);}
        function btnClick()
        {
            alert("came inside btn click");
            try
            {
                  window.webintent.startActivity({
                            action: window.plugins.webintent.ACTION_VIEW,
                            url: 'file:///storage/emulated/0/Download/anjali/Test.apk',
                            type: 'application/vnd.android.package-archive'
                        },
                        function(){ alert("inside success callback");},
                        function(){alert("inside error callback");}
                    );
            }
            catch(ex)
            {
                alert("Exception Error : "+ex);
            }
        }
    </script>
</html>

In the phone, only the exception error is thrown.

Reply as soon as possible.

0 Kudos
Anjali_P_
Beginner
2,200 Views

Attachments files:

0 Kudos
PaulF_IntelCorp
Employee
2,200 Views

I just exported a ZIP of my test file that I tried yesterday, unzipped it into a test folder, and built it using Cordova CLI. The image contains the problem plugin:

~/Downloads/tmp$ unzip ~/Downloads/third-party-plugin-pgb-cli-2017-0726-95045/platforms/android/build/outputs/apk/android-debug.apk
Archive:  ~/Downloads/third-party-plugin-pgb-cli-2017-0726-95045/platforms/android/build/outputs/apk/android-debug.apk
  inflating: AndroidManifest.xml     
  inflating: META-INF/CERT.RSA       
  inflating: META-INF/CERT.SF        
  inflating: META-INF/MANIFEST.MF    
  inflating: META-INF/rxjava.properties  
  inflating: META-INF/services/com.google.protobuf.GeneratedExtensionRegistryLoader  

...stuff deleted...

  inflating: third_party/java_src/error_prone/project/annotations/Google_internal.gwt.xml  
  inflating: third_party/java_src/jsr330_inject/Jsr330_inject.gwt.xml  
~/Downloads/tmp$ ll
total 7432
-rw-rw-rw-   1 test  staff    11K Dec 31  1979 AndroidManifest.xml
drwxr-xr-x   7 test  staff   238B Jul 26 10:58 META-INF/
drwxr-xr-x   3 test  staff   102B Jul 26 10:58 assets/
-rw-r--r--   1 test  staff   963B Dec 31  1979 build-data.properties
-rw-r--r--   1 test  staff   3.3M Dec 31  1979 classes.dex
drwxr-xr-x   3 test  staff   102B Jul 26 10:58 error_prone/
drwxr-xr-x   3 test  staff   102B Jul 26 10:58 javax/
drwxr-xr-x   3 test  staff   102B Jul 26 10:58 jsr305_annotations/
drwxr-xr-x   3 test  staff   102B Jul 26 10:58 jsr330_inject/
drwxr-xr-x  26 test  staff   884B Jul 26 10:58 res/
-rw-rw-rw-   1 test  staff   350K Dec 31  1979 resources.arsc
drwxr-xr-x   3 test  staff   102B Jul 26 10:58 third_party/
~/Downloads/tmp$ ll assets/
total 0
drwxr-xr-x  10 test  staff   340B Jul 26 10:58 www/
~/Downloads/tmp$ ll assets/www
total 168
drwxr-xr-x   6 test  staff   204B Jul 26 10:58 cordova-js-src/
-rw-r--r--   1 test  staff    71K Dec 31  1979 cordova.js
-rw-r--r--   1 test  staff   3.1K Dec 31  1979 cordova_plugins.js
drwxr-xr-x   3 test  staff   102B Jul 26 10:58 css/
-rw-r--r--   1 test  staff   4.4K Dec 31  1979 index.html
drwxr-xr-x   4 test  staff   136B Jul 26 10:58 js/
drwxr-xr-x  10 test  staff   340B Jul 26 10:58 plugins/
drwxr-xr-x   5 test  staff   170B Jul 26 10:58 xdk/
~/Downloads/tmp$ ll assets/www/plugins/
total 0
drwxr-xr-x  3 test  staff   102B Jul 26 10:58 com.borismus.webintent/
drwxr-xr-x  3 test  staff   102B Jul 26 10:58 cordova-plugin-battery-status/
drwxr-xr-x  3 test  staff   102B Jul 26 10:58 cordova-plugin-device/
drwxr-xr-x  3 test  staff   102B Jul 26 10:58 cordova-plugin-dialogs/
drwxr-xr-x  3 test  staff   102B Jul 26 10:58 cordova-plugin-screen-orientation/
drwxr-xr-x  3 test  staff   102B Jul 26 10:58 cordova-plugin-splashscreen/
drwxr-xr-x  3 test  staff   102B Jul 26 10:58 phonegap-plugin-barcodescanner/
drwxr-xr-x  3 test  staff   102B Jul 26 10:58 phonegap-plugin-push/ 

If you are not seeing the plugin inside your built APK, I would double-check the process you are using to create your CLI project and to build it. Did you try building with PhoneGap Build as a comparison point?

Likewise, I recommend you use the remote CDT debug tool to confirm what is present in your built and installed APK, similar to what I did (see my previous post and the links I've provided for additional help with that).

Just an observation, the way you are using Cordova CLI is somewhat unusual. It (and Node.js and npm) should be installed as globally accessible tools that are part of your path. You should not be creating Cordova projects inside of "C:\Program Files\nodejs\node_modules\npm" as you show in your images. And you should not have to run those tools as Administrator. I have a Windows machine and I am able to run all of those tools as a normal user, which is the expected usage model. This may be part of the problem...

0 Kudos
Anjali_P_
Beginner
2,200 Views

The problem was the webintent plugin is not recognized by the cordova cli with the help of NPM.Yesterday, I explicitly install the webintent plugin throughthe git hub client and then build the apk,After unzipping the apk file, in the assests folder I got the webintent plugin which is not present earlier.And with this apk file, installed in the phone and webintent plugin starts working.Thanks for your help and suggestions.

0 Kudos
Reply