4

I'm developing a communicator and I would like to expose my app to the native device as an app extension, allowing users to share images, text, videos from the native Share menu to my Cordova app. Is there a way to do this for a Cordova app on iOS, Android and Windows Store App?

Shawn
  • 41
  • 1
  • 3
  • http://stackoverflow.com/questions/27000201/how-can-i-share-an-image-to-my-cordova-phonegap-app-from-another-app/27034232#27034232 – jcesarmobile Feb 09 '15 at 08:09

3 Answers3

3

For Android this is easier and you can use a cordova plugin.

For iOS it is hard and I've documented this here

Community
  • 1
  • 1
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
1

If I understand correctly,

First, add android:sharedUserId="action.name" in manifest tag of Manifest.xml both the two apps. (nativa app and cordova app) The important thing is sharedUserId will be the same.

Second, save object for this code on native app.

SharedPreference prefs = context.getSharedPreferences(prefName, Activity.MODE_MULTI_PROCESS);

Last, you can get object for this code on cordova app.

Context con = cordova.getActivity().getApplicationContext().createPackageContext("action.name", Context.MODE_MULTI_PROCESS);
SharedPreferences pref = con.getSharedPreferences("prefName", Context.MODE_MULTI_PROCESS);
Soyeon Kim
  • 608
  • 7
  • 34
1

That's a good and still relevant question.

For iOS, the solution lies in creating a Share Extension to your iOS application, and luckily enough this process has been almost automated.

During my research, I tried to make use of the awesome cordova-plugin-openwith by Jean-Christophe Hoelt but faced several issues. The plugin is meant to receive share items of one type (say, URL, text or image), which is configured during installation. Also, with its current implementation, writing a note to share and selecting a receiver in a Cordova app are two different steps in different (native and Cordova) context, so it didn't look as a good user experience to me.

I made these and other corrections to this plugin and published it as a separate plugin: https://github.com/EternallLight/cordova-plugin-openwith-ios

If you need to receive only one type shares, say only photos, cordova-plugin-openwith should be fine. However, you will still be able to share one image at a time.

Note that it works only for iOS, not for Android.

EternalLight
  • 1,323
  • 1
  • 11
  • 19