0

I'm trying to share an image using the "share with" function from another app to my Ionic 4 app. My app has to handle the image and use it. I've tried this solution but it is for Ionic 3. The plugins seems to be not mantained anymore. There has to be a solution for such a common task in Ionic 4.

I've tried the darryncampbell-cordova-plugin-intent without success. My code is

    initializeApp() {
            this.platform.ready().then(() => {
                (<any>window).plugins.intentShim.registerBroadcastReceiver({
                    filterActions: [
                        'com.darryncampbell.cordova.plugin.broadcastIntent.ACTION'
                    ],
                    filterCategories: [
                        'android.intent.category.DEFAULT',
                    ],
                }, (intent) => {
                    //your code to be executed after the broadcast is received..
                    console.log('Received Intent: ' + JSON.stringify(intent.extras));
                });
            //more code...

This code do nothing. Nothing at all. Iwas able to edit my config.xml to configure the manifest so my app shows up in the share with menus. This works well.

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>
Alejandro del Río
  • 3,966
  • 3
  • 33
  • 31

1 Answers1

2

I know this was late replay, but thought it will help someone..

We used cordova-plugin-openwith plugin to achieve this, where this helps us to share an image using the "share with" function from another app to our Ionic 4 app.

We can initialize the plugin with below code in constructor of the App Component.

     // Initialize the plugin
     window.plugins.openwith.init((initSuccess) => {
          console.log('init success!' + initSuccess);
     }, (initError) => {
          console.log('init failed: ' + initError);
     });

We can add event handlers then after..

     window.plugins.openwith.addHandler((intent) => {
           console.log('intent received');

           let fileType = '';
           for (const item of intent.items) {
              // const item = intent.items[i];
              console.log('  type: ', item.type);   // mime type
              console.log('  uri:  ', item.uri);
           }
     });

Hope this helps.. :)

Ganesh
  • 5,808
  • 2
  • 21
  • 41