Coder Social home page Coder Social logo

cordova-webintent's Introduction

WebIntent Android Plugin for Cordova

History

Intention to maintain

This repo is actively maintained. Please feel free to treat it as the canonical upstream, and submit PRs for any changes you'd like merged.

Adding this plugin to your project

  1. To install the plugin, use the Cordova CLI:

    cordova plugin add github:cordova-misc/cordova-webintent.git
  2. Confirm that the following is now in your package.json file:

    "cordova-webintent": "github:cordova-misc/cordova-webintent

Sample code

Here is an example of using webintent to open an Android .apk package, which then launches the Installer:

window.plugins.webintent.startActivity({
      action: window.plugins.webintent.ACTION_VIEW,
      url: 'file://' + theFile.fullPath,
      type: 'application/vnd.android.package-archive'
    },
    function () {},
    function () {
      alert('Failed to open URL via Android Intent.');
      console.log('Failed to open URL via Android Intent. URL: ' + theFile.fullPath);
    }
);

Using the plugin

The plugin creates the object window.plugins.webintent with five methods:

startActivity

Launches an Android intent. For example:

window.plugins.webintent.startActivity({
    action: window.plugins.webintent.ACTION_VIEW,
    url: 'geo:0,0?q=' + address},
    function () {},
    function () { alert('Failed to open URL via Android Intent'); }
);

hasExtra

Checks if this app was invoked with the specified extra. For example:

window.plugins.webintent.hasExtra(WebIntent.EXTRA_TEXT,
    function (has) {
        // `has` is true iff app invoked with specified extra
    }, function () {
        // `hasExtra` check failed
    }
);

getExtra

Gets the extra that this app was invoked with. For example:

window.plugins.webintent.getExtra(WebIntent.EXTRA_TEXT,
    function (url) {
        // `url` is the value of EXTRA_TEXT
    }, function () {
        // There was no extra supplied.
    }
);

getUri

Gets the URI the app was invoked with. For example:

window.plugins.webintent.getUri(function (uri) {
    if (uri !== '') {
        // `uri` is the uri the intent was launched with.
        //
        // If this is the first run after the app was installed via a link with an install referrer
        // (e.g. https://play.google.com/store/apps/details?id=com.example.app&referrer=referrer.com)
        // then the Play Store will have fired an INSTALL_REFERRER intent that this plugin handles,
        // and `uri` will contain the referrer value ("referrer.com" in the example above).
        // ref: https://help.tune.com/marketing-console/how-google-play-install-referrer-works/
    }
});

onNewIntent

Gets called when onNewIntent is called for the parent activity. Used in only certain launchModes. For example:

window.plugins.webintent.onNewIntent(function (uri) {
    if (uri !== '') {
        // `uri` is the uri that was passed to onNewIntent
    }
});

sendBroadcast

Sends a custom intent passing optional extras

window.plugins.webintent.sendBroadcast({
    action: 'com.dummybroadcast.action.triggerthing',
    extras: { option: true }
  }, function() {
  }, function() {
});

Licence

The MIT License

Copyright (c) 2010-2017 Boris Smus and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cordova-webintent's People

Contributors

alalamav avatar chrisekelley avatar initsogar avatar jab avatar jrstarke avatar torsten-simon avatar zx9597446 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cordova-webintent's Issues

questions

I've been trying to make this plugin work for one of my projects but I keep getting a null value for uri (or sometimes empty string) when I share an image etc from another app.

Now, I'm confused if I even understand the purpose of this project.

I wanted to let users share content from other apps/websites with my app. First of all, the plugin by itself did not do anything, then I had to follow some configuration suggestions at Initsogar/cordova-webintent project then the app started showing up in share control on other apps.

I must also admit that I did not try running startActivity function yet as I thought it was not needed for receiving content from other apps. Is it necessary? If yes, what needs to go in url?

Apk file installation fails

If you download and install an api file, and try to do this:
window.plugins.webintent.startActivity(
{
action:window.plugins.webintent.ACTION_VIEW,
url:fileEntry.toURL(),
type:'application/vnd.android.package-archive'
},
function() {
...

You get these errors in the console:
/FileTransfer( 4326): download http://192.168.1.11/android/RestaurantSuite.apk to file:///data/data/com.restaurantsuite.restaurantsuite/files/files/RestaurantSuite.apk
D/FileTransfer( 4326): Download file:http://192.168.1.11/android/RestaurantSuite.apk
D/FileTransfer( 4326): Saved file: file:///data/data/com.restaurantsuite.restaurantsuite/files/files/RestaurantSuite.apk
I/ActivityManager( 1482): START u0 {act=android.intent.action.VIEW dat=file:///RestaurantSuite.apk typ=application/vnd.android.package-archive cmp=com.android.packageinstaller/.PackageInstallerActivity} from uid 10056 on display 0
D/CordovaActivity( 4326): Paused the activity.
W/asset ( 2402): Asset path /RestaurantSuite.apk is neither a directory nor file (type=1).
W/PackageInstaller( 2402): Parse error when parsing manifest. Discontinuing installation

The apk file is downloading fine. I've even put debug messages in to ensure that the size of the downloaded file is the same as the size of the original file on the server.

This is the very last thing which is preventing my app from being able to update itself when a new release is applied to a specific subscriber, which is a VERY IMPORTANT feature for this app, as the API between the app and the backend is subject to change, and EVERY TIME the app runs, it MUST be the same version as what the backend API is expecting, otherwiwse certain features may or may not work reliably.

Cordova version 8.0.0
Android API version 27

Please fix.
Thanks!

Error when running cordova prepare

Running cordova prepare on a fresh clone of a cordova project that uses your plugin results in the following error:

Failed to restore plugin "com.borismus.webintent" from config.xml. You might need to try adding it again. Error: Failed to fetch plugin com.borismus.webintent@https://github.com/cordova-misc/cordova-webintent.git via registry. Probably this is either a connection problem, or plugin spec is incorrect. Check your connection and plugin name/version/URL. Failed to get absolute path to installed module

Any chance you could fix the plugin definition so we don't have to go hunting through the one hundred and eighty three forks or add yet another one to get this to work? Thanks!

new release

Now that the install referrer intent handling is merged to master, would it be a good time to bump the version in plugin.xml, create and push a corresponding git tag, and then add the release notes to the corresponding entry that GitHub will add to https://github.com/chrisekelley/cordova-webintent/releases?

That should allow users of this plugin who want to use the new functionality to update their dependency to the new release version.

Android 9 (pie) issue

I am able to make this work in android 6
but when i tried updating my app in android 9 it says
Failed to open URL via Android Intent.

does this have any limitation as of the moment?

cannot debug

The startActivity fail handler actually does not give any data about failing.

It would be very useful if some data is returned when startActivity fails:

window.plugins.webintent.startActivity({
    action: window.plugins.webintent.ACTION_VIEW,
    url: 'geo:0,0?q=' + address},
    function () {},
    function (SOMETHING_TO_UNDERSTAND_SITUATION) {
    console.error('Failed to open URL via Android Intent',SOMETHING_TO_UNDERSTAND_SITUATION);
    }
);

is it possible to add this?

Getting Returned Data

I am successfully using the plugin to pull up another app. However, I need to get the result from the app. I don't see an option to startActivityForResult. Is this possible and something I am just missing in the plugin?

Silent Installation

Hi

Is there a possibility to do silent installation through this plugin?

thanks
rex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.