How to use a cordova plugin?

I am new to volt and so far loving how easy it is to use and deploy.

I don’t fully understand how to use a plugin and having trouble with it.

I am using a complete bare bones start

so i start with:

  1. cordova create MyApp

  2. cd MyApp

  3. cordova plugin add cordova-plugin-x-socialsharing (This one is on the volt supported plug)

  4. cordova platform add android

  5. cordova plugin ls
    cordova-plugin-x-socialsharing 6.0.3 “SocialSharing”
    es6-promise-plugin 4.2.2 “Promise”

  6. my index.js file

document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
    // Cordova is now initialized. Have fun!
}

$(document).on("click", '.shareBtn', function(){
    var options = {
        message: "Share app",
        files: ['', ''],
        url: "https://developer.mozilla.org",
        chooserTitle: "Share this app"
    }
    
    function socialSharing(){
        window.plugins.socialsharing.shareWithOptions(options)
    }
    
    try {
        socialSharing()
    } catch(err) {
        alert(err)
    }
})
  1. zip everything up to voltbuilder and get apk debug and then test on phone

  2. Get error: " TypeError: Cannot read properties of undefined (reading ‘socialsharing’) "

  3. my config file looks like this:

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloCordova</name>
    <description>Sample Apache Cordova App</description>
    <author email="dev@cordova.apache.org" href="https://cordova.apache.org">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
</widget>

Been lost for hours now.

Sounds like you’re off to a good start.

Steps 1-5 aren’t really needed, so long as you have a directory structure as shown here.

The preferred way to add a plugin to a project is to put a plugin line into your config.xml file, like this:

<plugin name="cordova-plugin-x-socialsharing" />

Add that line and try again.

It should be noted that this particular plugin is no longer supported and won’t work with Android 12.

Thanks. Will test it tomorrow when build limit resets.

That makes it much easier without even having to use Cordova and by just adding plugins in config.xml.

Is there an up to date plugin for sharing my app?

This sounds like a separate topic. Can you create a new issue with it? (also, not quite sure what you are asking here)