Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova receive shared data from other app

At first please do not mar this question as duplicate. All other questions are old and I've tried solutions from most of them and none of them work.

I'm working on an Android app and I'd added my app to share Android menu. I'd like to add functionality so if user clicks my app on the share list e.g. in Chrome browser or Google Drive app, my app will receive the data from that app e.g. from Chrome it wold be URL.

I've tried to use different plugins and read many posts about how to use intent in my app. Unfortunately none of them work. I've tried:

  • Sending url to ionic android app via webintents from another app - this one looked very promising
  • https://www.npmjs.com/package/phonegap-webintent
  • https://github.com/napolitano/cordova-plugin-intent - this one looked promising as well
  • https://github.com/okwei2000/webintent
  • https://github.com/stample/cordova-sharingreceptor

Did anyone got this working? My AndroidManifest.xml is as follows - the part about intent:

        <intent-filter android:label="@string/launcher_name">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <action android:name="android.intent.action.SEND_MULTIPLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>

In my config.xml I have:

<preference name="AndroidLaunchMode" value="singleTask" />

And I'm not getting data I'm expecting.

When I'm using https://github.com/napolitano/cordova-plugin-intent plugin I'm getting the intent but clipItems element is missing and the plugin is useless.

What am I doing wrong?

Any help appreciated.

like image 512
Strabek Avatar asked Nov 15 '25 14:11

Strabek


1 Answers

Finally I've done it. I used https://github.com/napolitano/cordova-plugin-intent ver 0.1.3 and

window.plugins.intent.setNewIntentHandler(function (intent) {
    // To get browser URL I had to use
    var subject = intent.extras['android.intent.extra.SUBJECT'];
    var url = intent.extras['android.intent.extra.TEXT'];
    // For Chrome, Opera and FireFox it works. For build in Android browser TEXT holds page title and URL joined with +
});

Although ver 0.1.3 has

window.plugins.intent.getRealPathFromContentUrl(contentUrl, function (realPath) {}, function () {});

available I couldn't use it because this didn't give me the data I wanted. contentUrl is different for differen browsers e.g. for Chrome it is uri and for build in Android browser it's text.

I installed ver 0.1.3 using CLI

phonegap plugin add https://github.com/napolitano/cordova-plugin-intent.git#61a47ae8c28a62004eeff4ed96a6f3c64c271a16

I couldn't add it using tag in config.xml

I hope this will help others.

like image 83
Strabek Avatar answered Nov 17 '25 10:11

Strabek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!