Make Ionic app appear in “Share” list and receive data

感情迁移 提交于 2019-11-28 18:48:57
Gandhi

After some detailed analysis, this is what I could conclude:

In Android, you could just get your application added in the share list using cordova-plugin-intent as described here. You can also achieve this by adding intent filter in the activity as described here

In iOS, this is bit tricky as there are no straight forward plugins or readymade solution available to achieve this. But the best possible link i could get related to adding app in iOS share menu is getting listed in share menu The link includes apple documentation to do this and also some tweaking in Info.plist to acheive this.

This is the best possible answer I could think of. Hope it helps. Cheers.

For running the plugin https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent, try:

  • Install the plugin with --save to make sure the plugin is added to your config.xml

    ionic plugin add https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent --save
    
  • Since this plugin is not imported in ionic-native, you need to identify the global object. This will be declared in the plugin folder->plugin.xml. Here the object is intentShim.

       <js-module name="IntentShim" src="www/IntentShim.js">
          <clobbers target="intentShim" />
      </js-module>
    
  • In your code declare global object as:

    declare var intentShim:any;
    

    And in your function,

    private registerBroadcastReceiver(){
      intentShim.registerBroadcastReceiver({
          filterActions: [
              'com.darryncampbell.cordova.plugin.broadcastIntent.ACTION'
              ]
          },
          function(intent) {
              //  Broadcast received
              console.log('Received Intent: ' + JSON.stringify(intent.extras));
          }
      );
    }
    

try

window.intentShim.registerBroadcastReceiver

or call function inside

document.addEventListener('deviceready', function(){
    registerBroadcastReceiver() }, 
false);

You can send or receive data through webIntent plugin provided by ionic.

Ionic:
   Ionic CLI          : 5.0.2 (C:\Windows\System32\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.5
   @ionic/app-scripts : 3.2.2

Cordova:
   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.0, (and 5 other plugins)

Utility:
   cordova-res : not installed
   native-run  : 0.2.5

System:
   Android SDK Tools : 26.1.1 (D:\Android\Sdk)
   NodeJS            : v12.4.0 (D:\node.exe)
   npm               : 6.9.0
   OS                : Windows 8.1

Command to install plugin:

ionic cordova plugin add com-darryncampbell-cordova-plugin-intent
npm install --save @ionic-native/web-intent@4

Code To receive data: (Add 'Web-Intent' in provider)

import { WebIntent } from '@ionic-native/web-intent';

clickMe() {
    console.log('clicked')
    this.webIntent.getIntent().then((data) => {
      console.log('Success', data);
    },
    err => {
      console.log('Error', err);
    });
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!