Giter VIP home page Giter VIP logo

darryncampbell-cordova-plugin-intent's Introduction

Please be aware that this application / sample is provided as-is for demonstration purposes without any guarantee of support

npm version npm downloads npm downloads npm licence

Note: this is the current underlying implementation for https://www.npmjs.com/package/@ionic-native/web-intent and https://ionicframework.com/docs/native/web-intent/

Android X support

  • For Android X Support please use version >= 2.x.x
  • For Android Support Library please use version 1.3.x

Interaction with Camera Plugin

If you are installing this plugin along with cordova-plugin-camera you MUST install cordova-plugin-camera first.

Overview

This Cordova plugin provides a general purpose shim layer for the Android intent mechanism, exposing various ways to handle sending and receiving intents.

Credits

This project uses code released under the following MIT projects:

IntentShim

This plugin defines a window.plugins.intentShim object which provides an API for interacting with the Android intent mechanism on any Android device.

Testing / Example

An example application is available at https://github.com/darryncampbell/plugin-intent-api-exerciser to demonstrate the API and can be used to test the functionality.

Installation

Cordova Version < 7

cordova plugin add https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent.git

Cordova Version >= 7

cordova plugin add com-darryncampbell-cordova-plugin-intent

Use with PhoneGap

Please use the latest PhoneGap cli when including this plugin, please refer to Issue 63 for context.

Supported Platforms

  • Android

intentShim.registerBroadcastReceiver

Registers a broadcast receiver for the specified filters

window.plugins.intentShim.registerBroadcastReceiver(filters, callback);

Description

The intentShim.registerBroadcastReceiver function registers a dynamic broadcast receiver for the specified list of filters and invokes the specified callback when any of those filters are received

Example

Register a broadcast receiver for two filters:

window.plugins.intentShim.registerBroadcastReceiver({
    filterActions: [
        'com.darryncampbell.cordova.plugin.broadcastIntent.ACTION',
        'com.darryncampbell.cordova.plugin.broadcastIntent.ACTION_2'
        ]
    },
    function(intent) {
        console.log('Received broadcast intent: ' + JSON.stringify(intent.extras));
    }
);

intentShim.unregisterBroadcastReceiver

Unregisters any BroadcastRecivers

window.plugins.intentShim.unregisterBroadcastReceiver();

Description

The intentShim.unregisterBroadcastReceiver function unregisters all broadcast receivers registered with intentShim.registerBroadcastReceiver(filters, callback);. No further broadcasts will be received for any registered filter after this call.

Android Quirks

The developer is responsible for calling unregister / register when their application goes into the background or comes back to the foreground, if desired.

Example

Unregister the broadcast receiver when the application receives an onPause event:

bindEvents: function() {
    document.addEventListener('pause', this.onPause, false);
},
onPause: function()
{
    window.plugins.intentShim.unregisterBroadcastReceiver();
}

intentShim.sendBroadcast

Sends a broadcast intent

window.plugins.intentShim.sendBroadcast(action, extras, successCallback, failureCallback);

Description

The intentShim.sendBroadcast function sends an Android broadcast intent with a specified action

Example

Send a broadcast intent to a specified action that contains a random number in the extras

window.plugins.intentShim.startActivity(
    {
        action: "com.darryncampbell.cordova.plugin.intent.ACTION",
        extras: {
                'random.number': Math.floor((Math.random() * 1000) + 1)
        }
    },
    function() {},
    function() {alert('Failed to open URL via Android Intent')}
);

intentShim.onIntent

Returns the content of the intent used whenever the application activity is launched

window.plugins.intentShim.onIntent(callback);

Description

The intentShim.onIntent function returns the intent which launched the Activity and maps to the Android Activity's onNewIntent() method, https://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent). The registered callback is invoked whenever the activity is launched

Android Quirks

By default the android application will be created with launch mode set to 'SingleTop'. If you wish to change this to 'SingleTask' you can do so by modifying config.xml as follows:

<platform name="android">
    ...
    <preference name="AndroidLaunchMode" value="singleTask"/>
</platform>

See https://www.mobomo.com/2011/06/android-understanding-activity-launchmode/ for more information on the differences between the two.

Example

Registers a callback to be invoked

window.plugins.intentShim.onIntent(function (intent) {
    console.log('Received Intent: ' + JSON.stringify(intent.extras));
});

intentShim.startActivity

Starts a new activity using an intent built from action, url, type, extras or some subset of those parameters

window.plugins.intentShim.startActivity(params, successCallback, failureCallback);

Description

The intentShim.startActivity function maps to Android's activity method startActivity, https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent) to launch a new activity.

Android Quirks

Some common actions are defined as constants in the plugin, see below.

Examples

Launch the maps activity

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

Launch the web browser

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

intentShim.getIntent

Retrieves the intent that launched the activity

window.plugins.intentShim.getIntent(resultCallback, failureCallback);

Description

The intentShim.getIntent function maps to Android's activity method getIntent, https://developer.android.com/reference/android/app/Activity.html#getIntent() to return the intent that started this activity.

Example

window.plugins.intentShim.getIntent(
    function(intent)
    {
        console.log('Action' + JSON.stringify(intent.action));
        var intentExtras = intent.extras;
        if (intentExtras == null)
            intentExtras = "No extras in intent";
        console.log('Launch Intent Extras: ' + JSON.stringify(intentExtras));
    },
    function()
    {
        console.log('Error getting launch intent');
    });

intentShim.startActivityForResult

Starts a new activity and return the result to the application

window.plugins.intentShim.startActivityForResult(params, resultCallback, failureCallback);

Description

The intentShim.startActivityForResult function maps to Android's activity method startActivityForResult, https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int) to launch a new activity and the resulting data is returned via the resultCallback.

Android Quirks

Some common actions are defined as constants in the plugin, see below.

Example

Pick an Android contact

window.plugins.intentShim.startActivityForResult(
{
    action: window.plugins.intentShim.ACTION_PICK,
    url: "content://com.android.contacts/contacts",
    requestCode: 1
},
function(intent)
{
    if (intent.extras.requestCode == 1)
    {
        console.log('Picked contact: ' + intent.data);
    }
},
function()
{
    console.log("StartActivityForResult failure");
});

intentShim.sendResult

Assuming this application was started with intentShim.startActivityForResult, send a result back

window.plugins.intentShim.sendResult(args, callback);

Description

The intentShim.sendResult function returns an Activity.RESULT_OK Intent to the activity that started this application, along with any extras that you want to send along (as args.extras object), and a callback function. It then calls Android Activity's finish() method, https://developer.android.com/reference/android/app/Activity.html#finish().

Android Quirks

Both args and callback arguments have to be provided. If you do not need the functionality, send an empty object and an empty function

window.plugins.intentShim.sendResult({}, function() {});

Example

window.plugins.intentShim.sendResult(
    {
        extras: {
            'Test Intent': 'Successfully sent',
            'Test Intent int': 42,
            'Test Intent bool': true,
            'Test Intent double': parseFloat("142.12")
        }
    },
    function() {
    
    }
);

intentShim.packageExists

Returns a boolean indicating if a specific package is installed on the device.

window.plugins.intentShim.packageExists(packageName, callback);

Description

The intentShim.packageExists function returns a boolean indicating if a specific package is installed on the current device.

Example

const packageName = 'com.android.contacts';

window.plugins.intentShim.packageExists(packageName, (exists) => {
    if (exists) {
        console.log(`${packageName} exists!`);
    } else {
        console.log(`${packageName} does not exist...`);
    }
});

Predefined Constants

The following constants are defined in the plugin for use in JavaScript

  • window.plugins.intentShim.ACTION_SEND
  • window.plugins.intentShim.ACTION_VIEW
  • window.plugins.intentShim.EXTRA_TEXT
  • window.plugins.intentShim.EXTRA_SUBJECT
  • window.plugins.intentShim.EXTRA_STREAM
  • window.plugins.intentShim.EXTRA_EMAIL
  • window.plugins.intentShim.ACTION_CALL
  • window.plugins.intentShim.ACTION_SENDTO
  • window.plugins.intentShim.ACTION_GET_CONTENT
  • window.plugins.intentShim.ACTION_PICK

Tested Versions

Tested with Cordova version 6.5.0 and Cordova Android version 6.2.1

darryncampbell-cordova-plugin-intent's People

Contributors

artlogic avatar cortexml avatar darryncampbell avatar epoxa avatar fquirin avatar jan-jockusch avatar jdgjsag67251 avatar mattdsteele avatar mcelotti avatar nachomozo avatar redwolf2 avatar robwatt avatar zbynekstara 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  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  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  avatar  avatar

darryncampbell-cordova-plugin-intent's Issues

problem using StartActivityForResult

my code is

window.plugins.intentShim.startActivityForResult( { action: window.plugins.intentShim.ACTION_SEND, component: "another.app.com/.Activity.PaymentRequestActivity", extras: { 'authCode': '2817EB9BDD7tvnsisygchlxe25719E053340B10AC5316', } }, function(intent) { console.log('problem '); }, function() { console.log("StartActivityForResult failure"); });

and sample java code is:

Intent intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(new ComponentName("another.app.com", "another.app.com.Activity.PaymentRequestActivity")); intent.putExtra("authCode", "2817EB9BDD7tvnsisygchlxe25719E053340B10AC5316"); startActivityForResult(intent, result);

but my code not work,,

and component not opened

Get build Error when adding 'darryncampbell-cordova-plugin-intent'

Hello,

when I add the plugin I get the folling error:
`A problem occurred configuring root project 'android'.

Could not resolve all dependencies for configuration ':_debugApkCopy'.
Could not find com.android.support:support-v4:27.1.0.
Searched in the following locations: ....
`
Angular-Cli: 6.1.4
Cordova: 8.0.0

When I remove the plugin everything works fine.

Install the WebIntent plugin: 'ionic cordova plugin add com-darryncampbell-cordova-plugin-intent'

When i want to use the Ionic Native WebIntent plugin, i always have this error Install the WebIntent plugin: 'ionic cordova plugin add com-darryncampbell-cordova-plugin-intent', but it's already installed like this :
$ ionic cordova plugin add com-darryncampbell-cordova-plugin-intent
$ npm install --save ionic-native/web-intent

@ionic/cli-plugin-cordova : 1.6.2
@ionic/cli-plugin-ionic-angular : 1.4.1
@ionic/cli-utils : 1.7.0
ionic (Ionic CLI) : 3.7.0

global packages:

Cordova CLI : 7.0.1 

local packages:

@ionic/app-scripts : 1.3.12
Cordova Platforms  : android 6.2.3 ios 4.4.0
Ionic Framework    : ionic-angular 3.5.0

System:

Node       : v6.6.0
OS         : macOS Sierra
Xcode      : Xcode 8.3.3 Build version 8E3004b 
ios-deploy : 1.9.0 
ios-sim    : 6.0.0 
npm        : 5.3.0 

Ionic send broadcast with intent and extra values

I don't know how to add intent in sendbroadcast and put extra array list of strings also adding FLAG_INCLUDE_STOPPED_PACKAGES and component to be like the below native code :

  ArrayList<String> messageList =  new ArrayList<String>();
  messageList.add( "51541545" );
  messageList.add("nbvnv");

  final Intent intent =new Intent();
  intent.setAction( "customReciver.sms.4gtss" );;
  intent.putStringArrayListExtra("infoList", messageList);
  intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
  intent.setComponent(new ComponentName("com.example.mustafa.recieverapp","com.example.mustafa.recieverapp.MyBroadcastReceiver"));
  sendBroadcast(intent);

Is it posibble to receive intent data when the app is closed?

On Android 6.0.1. I have the plugin working perfectly when the cordova app is open, but when I close the cordova app and go to other app (like Pinterest, Chrome, Facebook) and try to send data to my app again, the onIntent event is not triggered.

Any idea about how to solve this?

Thanks for this amazing plugin.

Unable to open local file with startActivity

I have the path to a file from another plugin. I've tried the following to open the file in a default application:

window.plugins.intentShim.startActivity(
{
    action: window.plugins.intentShim.ACTION_VIEW,
    url: '/path/to/file.jpg'
},
function() {console.log('success');},
function() {console.error('Failed')};
);
window.plugins.intentShim.startActivity(
{
    action: window.plugins.intentShim.ACTION_VIEW,
    url: 'file:///path/to/file.jpg'
},
function() {console.log('success');},
function() {console.error('Failed')};
);
window.plugins.intentShim.startActivity(
{
    action: window.plugins.intentShim.ACTION_VIEW,
    url: 'file://path/to/file.jpg'
},
function() {console.log('success');},
function() {console.error('Failed')};
);

All three of these failed.

Problem with the camera installed first

I installed the plugin of the camera first, but the camera does not work with the latest version of this plugin.

How should I proceed to force the loading order of the plugins?

Thank

Blank Page

Hi.
I'm currently building an Android app with Ionic 3, where I want to save links which should be sent from Chrome via Intent to my app.

I am trying to use the WebIntent like it is described here:
https://ionicframework.com/docs/native/web-intent/

This is what I am doing right now, but I always get a blank page when it's opened (my regular content isn't loaded).

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { WebIntent } from '@ionic-native/web-intent';

@Component({
  selector: 'page-stream',
  templateUrl: 'stream.html'
})
export class StreamPage {

  intent : WebIntent;

  constructor(public navCtrl: NavController, public webIntent : WebIntent) { 
    this.intent = webIntent;
  }

  ionViewDidLoad() {
    let filter = [
      'com.darryncampbell.cordova.plugin.intent.ACTION'
    ];

    this.intent.registerBroadcastReceiver(filter);

    let result = this.intent.getIntent();
    console.log(result);
  } 
}

Do I use it the right way? Could somebody help me to get this working?
Thank you so much!

Update:
Ok, i forgot to add the plugin to the providers in app.modules.
But now I get the error 'plugin_not_installed', but I installed the plugin. I think this is the same issue: danielsogl/awesome-cordova-plugins#1609. --> Fixed it!

startService(intent)

Hi,

I've been given this code example :

Android.Content.Intent intent = new Android.Content.Intent("fr.namespace.intent.action.stop.barcode.service");
intent.SetPackage("fr.namespace.service.device");
startService(intent)

but i'm not sure the startService(intent) is possible with your package. Did I miss something ?

Thanks

How can we share multiple files from the file manager using darryncampbell-cordova-plugin-intent

I'm using the ionic framework,
Unable to share my documents with my app.
Please tell me what I have to do

here is my code :
document.addEventListener('deviceReady', function(){
alert(JSON.stringify(window.plugins.intentShim));
window.plugins.intentShim.getIntent(
function(intent)
{
var intentExtras = intent.extras;
if (intentExtras == null)
intentExtras = "No extras in intent";
alert('Launch Intent Extras: ' + JSON.stringify(intentExtras));
},
function()
{
alert('Error getting launch intent');
});

});

Thanks in advance

How to call intent for ACTION_VIDEO_CAPTURE

First of all, sorry for my poor English.

I'm trying to call startActivityForResult to capture vídeo, without success :(

Google a lot of hours, read source code and can't figure how to use this plugin to call Photo & Video register Action.

App is not receiving Broadcast intent

Another apps shares an url and my app should offer himself to handle it. Nevertheless my app is not appearing on the share list. Also, there is an runtime error if I remove the broadcast callback, if I add the callback the compiler throws an error...

Could you show a working sample for the latest Ionic version?

ERROR TypeError: Wrong type for parameter "successCallback" of IntentShim.getIntent: Expected Function, but got Undefined. at Object.checkArgs (cordova.js:428) at IntentShim.getIntent (plugins/com-darryncampbell-cordova-plugin-intent/www/IntentShim.js:74)

`ionViewDidLoad() {
console.log ("ionViewDidLoad");

  this.intent.registerBroadcastReceiver({
    filterActions: [
        this.intent.ACTION_SEND
        ], 
    filterCategories: [
          'com.android.intent.category.DEFAULT'
          ]
  }/*, 
    function(intent) {
        //  Broadcast received
        console.log('Received Intent: ' + JSON.stringify(intent.extras));
    }*/
  );

  let result = this.intent.getIntent();
  console.log(result);
} 

AndroidLaunchMode singleTask cannot read intents

Hey, I'm using the intent-exerciser to test out the plugin in my own app. When I launch the intent-exerciser with singleTop launchmode, the intent is correctly read by the exerciser-app, but as soon as I switch it to singleTask, the intent can't be read anymore(the intent action is just shown as the default "android.intent.action.MAIN"). Have you encountered something similar?

Zebra DataWedge and Ionic 3 Not working

Hi. Any chance on getting an Ionic 3 update to this please?

I have a Zebra TC56 with physical scan button which I'm trying to get data from.

I have tried, but with no success.

My plugins are ...

com-darryncampbell-cordova-plugin-intent 1.0.0 "Intent Shim"
cordova-plugin-device 2.0.1 "Device"
cordova-plugin-ionic-keyboard 2.0.5 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.3 "Whitelist"

My home.ts code looks like this ...

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { WebIntent } from '@ionic-native/web-intent';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  data: any;

  constructor( public navCtrl: NavController, private webIntent: WebIntent ) {
    this.webIntent.startActivity( {
      action: this.webIntent.ACTION_VIEW,
      url: 'io.ionic.bp.ACTION',
      type: 'application/vnd.android.package-archive'
    } )
    .then(function( intent ){
      alert( JSON.stringify( intent.extras ) );
    }, function( err ) {
      alert( err );
    });
  }
}

I have also injected it into app.modules.ts.

I have also added the following into my AndroidManifest.xml file ...

<intent-filter>
   <action android:name="io.ionic.bp.ACTION" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

My config.xml has <widget id="io.ionic.bp" version="0.0.1" blah blah in it.

My DataWedge has an intent action of "io.ionic.bp.ACTION" and intent category has "android.intent.category.DEFAULT" and intent delivery of "Send via StartActivity."

When I run the app I get an error alert "Relative URIs are not supported." and then the alert changes to say "The connection to the server was unsuccessfull (file://android_asset/www.index.html)".

Any ideas?

check if there is an app installed that can handle the given intent

Currently the plugin is just firing an intent and don't cares if there is no app installed that can handle it. Nevertheless this is frequent error. Could you please extend it by this check?

 if (intent.resolveActivityInfo(mActivity.getPackageManager(), 0) != null) {
         mActivity.startActivity(intent);
} else {
        //throw error
 }

Convert getIntent() resulted path to actual path

Hello,

I needed to display shared images and save them in a separate folder but getIntent method was giving me uri. I have tried filePath.resolveNativePath() but this was throwing error.

getIntent() result
"uri": "content://0@media/external/images/media/1185", "type": "image/png", "extension": "png"

In plugin I have added "getRealPathFromURI_API19" as per suggestions at https://stackoverflow.com/questions/2789276/android-get-real-path-by-uri-getpath/2790688.

"file://" + getRealPathFromURI_API19 working result
/storage/emulated/0/DCIM/Camera/20180501_113549.jpg

Intent to install APK

Greetings..

Prior to nougat I was able to install apk with your plugin.
options = {
action: window.plugins.intentShim.ACTION_VIEW,
url: 'file:///storage/.....apk',
type: 'application/vnd.android.package-archive'
}
Nougat now requires a fileProvider and use the action ACTION_INSTALL_PACKAGE for the intent.
I am not skilled enough to modify your plugin.
Please advise..
Thank you in advance

Android N still failing with apk install using custom external directory

Greetings Darryn..
I'm Still having issue with Android N when installing apk from external file location.
I create my file paths using variables from the cordova file plugin.
eg : cordova.file.externalApplicationStorageDirectory + "downloads/my.apk";
will return url "file:///storage/emulated/0/Android/data/com.mycompany.myapp/downloads/my.apk"
Which allows me to install the apk using "window.plugins.intentShim.startActivity"
It fails on android N..
If you change line 92 in your intentShim.java
File uriAsFile = new File(Environment.getExternalStorageDirectory(), fileName);
to
File uriAsFile = new File(fileName);
It then works perfectly for any custom location
Currently it fails.

Thank you in advance for any consideration

Cheers..
Mark

How to share image to other apps

Hello,

Please show me some example coding for action SEND, and SEND_TO.
This is my code that not working

window.plugins.intentShim.startActivityForResult(
{
action: window.plugins.intentShim.ACTION_SEND,
requestCode: 1,
extras: {
"android.intent.extra.STREAM": "file:///storage/emulated/0/Pictures/test_album/2018-0-23-4.png"
}
},
function (intent) {
if (intent.extras.requestCode == 1 && intent.extras.resultCode == window.plugins.intentShim.RESULT_OK) {
alert('Picked contact: ' + intent.data);
document.getElementById('startActivityResultData').innerHTML = "Picked Contact: " + intent.data;
}
else {
document.getElementById('startActivityResultData').innerHTML = "Picked Contacted Canceled";
}
},
function (e) {
document.getElementById('startActivityResultData').innerHTML = "StartActivityForResult failure" + e;
}
);

Thank you

Web Intent - plugin_not_installed

(1)app.module.ts
providers:[WebIntent]

(2)package.json
"@ionic-native/web-intent": "3.10.2",

(3)config.xml

(4) after platform.ready().then(() => {}

global packages:

@ionic/cli-utils : 1.4.0
Cordova CLI : 6.5.0
Ionic CLI : 3.4.0
local packages:

@ionic/app-scripts : 1.3.7
@ionic/cli-plugin-cordova : 1.4.0
@ionic/cli-plugin-ionic-angular : 1.3.1
Cordova Platforms : android 6.1.2
Ionic Framework : ionic-angular 3.3.0
System:

Node : v6.11.0
OS : Windows 7
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 3.10.10

Update to 0.0.8 breaks build

After updating it gives error as it doesnt seems to be creating file_paths file. As in new update config-file will only change file if it already exists. It ignores the changes if the file is not present.

Total time: 6.05 secs
Error: /parking-genius/platforms/android/gradlew: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/parking-genius/platforms/android/build/intermediates/manifests/full/debug/AndroidManifest.xml:71:35-50: AAPT: No resource found that matches the given name (at 'resource' with value '@xml/file_paths').

/parking-genius/platforms/android/build/intermediates/manifests/full/debug/AndroidManifest.xml:69: error: Error: No resource found that matches the given name (at 'resource' with value '@xml/file_paths').



FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Set intent package

Is there a way to set the package to which I need to send an intend ?
For something like that :

Android.Content.Intent intent = new Android.Content.Intent("fr.myvendor.intent.action.stop.barcode.service");
intent.SetPackage("fr.myvendor.service.cfive");

Open external application

Hello and thanks for the plugin.
Is it posible to launch externall application after verifying if it is installed using startActivity method?

Can the intent be received on each page?

When my app is launched using an intent with extras, will window.plugins.intentShim.getIntent work on every page in my app or do I need to store the information in something like localStorage on the first page?

Can no longer build Cordova with this plugin

Hi,

I have been using this plugin, and it has been working great! However recent updates seem to have broken the plugin.

Create new project, add this and only this plugin.

cordova plugin add com-darryncampbell-cordova-plugin-intent
cordova platform add android
cordova run android

`:app:processDebugResourcesC:\Users\me.gradle\caches\transforms-1\files-1.1\support-compat-28.0.0-alpha1.aar\1cef07b5640ca04267708cb0ed9b2629\res\values\values.xml:20:5-70: AAPT: error: re
source android:attr/fontVariationSettings not found.

C:\Users\me.gradle\caches\transforms-1\files-1.1\support-compat-28.0.0-alpha1.aar\1cef07b5640ca04267708cb0ed9b2629\res\values\values.xml:20:5-70: AAPT: error: resource android:attr/ttcInd
ex not found.

C:\Projects\POS\cordova\platforms\android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:86: error: resource android:attr/fontVariationSettings n
ot found.
C:\Projects\POS\cordova\platforms\android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:86: error: resource android:attr/ttcIndex not found.
error: failed linking references.

FAILED
`

Cordova Version: 8.0.0
Android Version: Everything above 6.2.3 (it does work for this version)

It does work for 6.2.3, however i built a lot of applications on android 7.0.0 that are now failing. I would prefer to not have to regress my applications because I require this fantastic plugin.

Any help would be greatly appreciated.

onIntent() does not function on 1st restore from background

Hi,

My app requires the user to be able to open it from say the Photos app (sharing images). The user can select either a single image, or multiple images.

If I:

  1. launch the app through the LAUNCHER
  2. put the app in the background
  3. goto the Photos App
  4. share a photo to my app
    I will not receive an intent through onIntent()

If I repeat steps 2-4 again, I get an intent. It appears to be the correct one.

I have written a small Ionic app showing the issues

@Component({
  templateUrl: 'app.html'
})
export class MyApp implements OnDestroy {

  rootPage:any = HomePage;

  private onResumeSubscription: Subscription;

  constructor(platform: Platform,
              statusBar: StatusBar,
              splashScreen: SplashScreen) {

    platform.ready().then((readySource) => {
      console.log('platform.ready: ' + readySource);
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();

      // called on startup of the app - if opening using SEND or SEND_MULTIPLE will return the correct number of
      // clipItems & extras
      (<any>window).plugins.intentShim.getIntent(intent => {
        console.log('ready::getIntent');
        console.log(intent);
      }, (err) => {console.log(err);});

      this.onResumeSubscription = platform.resume.subscribe(() => {
        // resume is always called correctly.
        console.log('platform.resumed');

        // not called the 1st time from being put in the background after launching the app
        // repeated background/share attempts appear to yield the correct intent
        (<any>window).plugins.intentShim.onIntent(intent => {
          console.log('----- onIntent');
          console.log(intent);
        });
      });
    });
  }

  public ngOnDestroy(): void {
    this.onResumeSubscription.unsubscribe();
  }
}

These are the intent-filters I added

<intent-filter android:label="INTENT SEND">
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="*/*" />
</intent-filter>
<intent-filter android:label="INTENT SEND_MULTIPLE">
    <action android:name="android.intent.action.SEND_MULTIPLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="*/*" />
</intent-filter>

`
cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.0.0 

local packages:

@ionic/app-scripts : 3.1.9
Cordova Platforms  : android 7.0.0
Ionic Framework    : ionic-angular 3.9.2

`

Are you aware of this issue, or have I not integrated your plugin correctly?

Application not functioning well

After installing this plugin this worked great and am able to receive the notification but after that it failed on application performances.

Every time i need to call changededucter manually to effect the changes because of this the application has hell lot of blockers

Send result back to the caller

Hi, i am working on ionic v1 app and i installed this plugin to let another android app call mine, that part is fine, but, i don't see how my app can send a result to the caller, this plugin can do that?

another thing can i fork this plugin?, if not, can i work for it?

Possible change

Greetings Darryn..
Thanks for making changes so quickly. May I make a suggestion. Would it be possible to change your code on line 86 of IntentShim.java
File uriAsFile = new File(Environment.getExternalStorageDirectory(), fileName);
to
File uriAsFile = new File(uriAsString.replace("file://", "" ));

That way existing apk install intents would not have to change the file location. Apparently this will create a valid file from an existing file:///path.

Thank you for your consideration.

Calling finish for activity to close current app

I have an app that gets launched by another one. Is there a way to call finish() in this plugin to close the app that was opened and go back to the main app? I am thinking that the only existing way currently is to start the app using startActivityForResult and call sendResult. Is there a way without calling startActivityForResult or will that method even work? Let me know what I could do. Thanks!

plugin should set onload=true

Hi,

I ran into another issue.

One of the phones I am testing on (Samsung S7) appears to have a very aggressive memory manager. Basically, when an app goes in the background (and a different app is brought to the foreground), it's process is destroyed (even though it appears to remain in the background).

When I share a picture to this app, the intent provided to the app is correct, but it is shared via onNewIntent, instead of getIntent. To me this means the OS remembered that the app is in the background, even though process is dead.

Here are some logs of what I see.

When launching a different app (and my app is in the background)

CordovaActivity: Paused the activity.
CordovaActivity: Stopped the activity.
CordovaActivity: CordovaActivity.onDestroy()

Then when I share an image with my application I see the following. This is the correct intent I should see.

ActivityManager: START u0 {act=android.intent.action.SEND typ=image/* flg=0xb080001 cmp=ComponentInfo{io.ionic.starter/io.ionic.starter.MainActivity}}

Unfortunately, this intent does not appear to be available to my application (the plugin never receives it). I see this in the logs

CordovaActivity: Apache Cordova native platform version 7.0.0 is starting
CordovaActivity: CordovaActivity.onCreate()
CordovaActivity: Started the activity.
CordovaActivity: Resumed the activity.
...
Cordova Intents Shim: Action: getIntent
Cordova Intents Shim: getIntentIntent { act=android.intent.action.MAIN flg=0x10000000 cmp=io.ionic.starter/.MainActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } }

After doing some debugging in Cordova, I can see that Cordova does indeed get the correct Intent (android.intent.action.SEND), but Cordova receives this intent through onNewIntent(), and as such tries to send this to the plugin BEFORE the plugin has been created by Cordova, through onNewIntent(). This is because the plugin is set to only be created when it is invoked in my app (this is how the plugin was configured).

To fix this I added

<param name="onload" value="true"/>

To the plugin.xml. This will allow Cordova to create the plugin when Cordova is started.

In addition to this, a bit more code (in the same vein as issue #51) is also required. Because Cordova calls onNewIntent before calling execute() we won't have a context. And on top of that, Cordova will call the 'getIntent' action, not 'onNewIntent'.

Now the logs show:

...
CordovaActivity: Started the activity.
Cordova Intents Shim: onNewIntent: Intent { act=android.intent.action.SEND typ=image/* flg=0x13400001 cmp=io.ionic.starter/.MainActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } clip={image/* U:content://0@media/external/images/media/624} (has extras) }
CordovaActivity: Resumed the activity.
...
Cordova Intents Shim: Action: getIntent
Cordova Intents Shim: getIntent => deferredIntent: Intent { act=android.intent.action.SEND typ=image/* flg=0x13400001 cmp=io.ionic.starter/.MainActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } clip={image/* U:content://0@media/external/images/media/624} (has extras) }

I have run this against Cordova 6.4, 7.0, and 7.1. There does not appear to be any adverse side effects of having the plugin created when Cordova is started vs creating it on demand.

You can see my changes here (robwatt@7584a11). If you agree to them, I will create a pull request.

is it possible to uninstall app with intent ?

how to uninstall app with intent ?
how to implement following code ?
Uri packageUri = Uri.parse("package:org.klnusbaum.test");
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
startActivity(uninstallIntent);

IONIC Native Web Intent response is incorrect in specific case

Hi @darryncampbell

(NOTE:
GooglePay (earlier called Tez) is an India specific payment app launched by Google in India which uses UPI specification to facilitate in-app payment. This UPI payment provided Web Intent based mechanism to perform payment using Mobile App.

BHIM, PhonePe are apps similar to GooglePay but by other vendors)

  1. I am integrating Google Pay with my IONIC v3 based mobile app on Android Device using UPI Deep linking specification
    (using IONIC Native Web Intent plugin. This is shim layer for the Android intent mechanism)

  2. I call below method to invoke web intent. Through chooser I choose Google Pay (Tez) app . Payment is completed successfully.
    this.webIntent.startActivityForResult(intentOptions ).then(intentResponse=>{},err=>{});

  3. My Problem - What I receive in intent response is below even though payment is successful.
    {"extras":{"resultCode":0,"requestCode":1},"flags":0}

  4. Behaviour with other apps like BHIM or PhonePe (these are applications similar to Google Pay to perform payment). If I use other app like PhonePe or BHIM instead of GooglePay, it works perfectly
    This kind of behaviour I have seen only with GooglePay. There are more than 25+ such applications and (I tested more that 15) all those work perfectly

Success Response scenario by BHIM/PhonePe app
{"extras":{"resultCode":-1 , "response":"txnId=UPI586b8ee3d55b4405bfd30dab4b6b69bb&responseCode=00&ApprovalRefNo=null&Status=SUCCESS&txnRef=TR0001","requestCode":1},"flags":0}
This response format complies with request/response guidelines provided by NPCI/UPI Payment framework which all app providers like Google Pay, Phonepe, BHIM etc are expected to follow.

After successful payment, it is supposed to return “resultCode”= -1 and
provide “response” in the extras object. However the response is missing in extras

  1. I wrote a native android test program to invoke same Google Pay app.
    startActivityForResult(chooser, REQUEST_PAYMENT, null);
    if the payment is successful, it returns the response in expected manner. I can extract the response by calling
    Intent.getStringExtra("response"))

This probably implies the underlying Google Tez app behaves correctly.

  1. I suspect there is unique behaviour with Web Intent plugin ( IONIC native wrapper or cordova plugin version provided in maroon color below.) when response is returned by Google Pay to darryncampbell-cordova-plugin and sending that response back to my caller app
    o all other apps response excect GooglePay the response is correctly sent back to my caller app.

  2. Please advice
    o what may be wrong
    o what I can do to debug the IONIC native wrapper or cordova plugin or put console.log statements to deep dive.
    o What other information I should provide you to investigate further?

  3. My Environment Versions

    1. Mobile app – Android 6.0 and 7.0
    1. IONIC v3.20.0
    1. Web Intent
      a.
      b. "@ionic-native/web-intent": "^4.14.0",
    1. Ionic Framework
      a. ionic-angular 3.9.2
    1. System:
      a. Android SDK Tools : 26.1.1
      b. Node : v8.11.1
      c. npm : 6.0.0
      d. OS : Windows 10

Thank you and warm regards

Haresh Gujarathi
Business Development Partner
MindNerves Technology Services Pvt Ltd
Ph: +91 91724 30080

ionic 3 intent

hi. i need to send PDF to my app. can i do it with this plugin on ionic 3 and get it to send on server? i tried intent plugin on ionic 1 and it was quite easy to do. help pls and can you write a small guide for this.

Ionic Focussed Input Problem With Scanner And Datawedge

Hi,

i have a problem with focussed input. I don't want the content of the scanned QR-code put directly into the focussed input. I hope i can prevent this in the config of registerBroadcastReceiver...

Thx and best regards! :)

Ionic does not build with this plugin

Hello, I'm trying to install this plugin into my ionic project with the following versions:

  • ionic version: 3.20.0
  • cordova version: 8.0.0
  • darryncampbell-cordova-plugin-intent version: 1.0.2

But after installation, when I run: ionic cordova build android
I got this error:

`FAILURE: Build failed with an exception.

  • What went wrong:
    Could not resolve all files for configuration ':app:debugCompileClasspath'.

:app:generateDebugSources UP-TO-DATE
:app:javaPreCompileDebug FAILED
26 actionable tasks: 1 executed, 25 up-to-date
Could not find common.jar (android.arch.core:common:1.1.0).
Searched in the following locations:
https://jcenter.bintray.com/android/arch/core/common/1.1.0/common-1.1.0.jar

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1s
(node:18440) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • What went wrong:
    Could not resolve all files for configuration ':app:debugCompileClasspath'.

Could not find common.jar (android.arch.core:common:1.1.0).
Searched in the following locations:
https://jcenter.bintray.com/android/arch/core/common/1.1.0/common-1.1.0.jar

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1s
at ChildProcess.whenDone (D:\Soyou\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
(node:18440) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:18440) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.`

Can you know why it's doing this ?

Ionic registerBroadcastReceiver cannot be used with subscribe

Hi,

I've just been wondering the conflict of the code you mentioned in a pull request and the current code. The registerBroadcastReceiver returns void in the source code, but the code you mentioned before used subscribe.

If we can't use subscribe with registerBroadcastReceiver, then what is the correct way to get the message sent from Datawedge API?

this.webIntent.registerBroadcastReceiver({ filterActions: [ 'com.example.ACTION' ], filterCategories: [ 'android.intent.category.DEFAULT' ] }).subscribe((intent) => {console.log('Received Intent: ' + JSON.stringify(intent.extras));});

Thanks and regards

Open app in independent tab

Hi,
Is there a way we can open the app in independent tab? Currently, when I start a new activity, the new app is opening inside my current app. I want it to open in different tab, so that I see two separate windows(old app and currently opened app) in task manager. Currently, I see only one window in task manager.

Thanks,
Pooja

Duplicate FileProviders issue

Hi,

I am facing the below error while building my app in android after installing this plugin.
Ionic 3 project.

Element provider#android.support.v4.content.FileProvider at AndroidManifest.xml:49:9-51:20 duplicated with element declared at AndroidManifest.xml:33:9-35:20

AndroidManifest contains:-

<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>

<provider android:authorities="${applicationId}" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
</provider>

I think this might be because of clashing of some other native plugin. Here are the list of native plugins I am using:-

com-darryncampbell-cordova-plugin-intent 0.0.10 "Intent Shim"
com.megster.cordova.FileChooser 0.0.0 "File Chooser"
cordova-base64-to-gallery 4.1.2 "base64ToGallery"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-camera-preview 0.9.0 "cordova-plugin-camera-preview"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.7 "Console"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-filepath 1.0.2 "FilePath"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-secure-storage 2.6.8 "SecureStorage"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.3 "StatusBar"
cordova-plugin-whitelist 1.3.2 "Whitelist"
cordova-plugin-x-socialsharing 5.1.8 "SocialSharing"
cordova-sqlite-storage 2.0.4 "Cordova sqlite storage plugin"
cordova.plugins.diagnostic 3.6.5 "Diagnostic"
es6-promise-plugin 4.1.0 "Promise"
info.protonet.imageresizer 0.1.1 "Image Resizer"
ionic-plugin-deeplinks 1.0.15 "Ionic Deeplink Plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"

Please suggest a solution. Don't want to manually make builds after removing one provider.

Build error - Cannot find Symbol variable N

Hi,

I'm having build errors when creating a blank Cordova app with and only include the plugin.

IntentShim.java:359
if(Build.Version.SDK_INT >= Build.VERSION_CODES.N && uniAriString.startsWith("file://"))
symbol: variable N

Cordova version 6.31.

Any advice?

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.