I want my app to be listed in share options of other apps so that I can receive text, image or file. Is it possible to do this with Nativescript and if so, how?
Asked
Active
Viewed 629 times
1
-
You can see how it is done via the native Android and iOS and implementing it in NativeScript by accessing the same native APIs. The Android starting point would be here https://developer.android.com/training/sharing/receive#java – Nick Iliev Sep 18 '18 at 13:28
-
1It would be better if we had a ready-to-use solution but I will try this and if it works, I will share it here. Thanks. – zarax Sep 18 '18 at 20:52
1 Answers
2
Here is a POC demo app that demonstrates how to implement the above on Android with NativeScript. Just as in native Android I am overwriting the Activity onCreate
method and providing the intent logic.
Then the onCreate method is overwritten
application.android.on(application.AndroidApplication.activityCreatedEvent, function (args) { let activity = args.activity; // Get intent, action and MIME type let intent = activity.getIntent(); let action = intent.getAction(); let type = intent.getType(); if (android.content.Intent.ACTION_SEND === action && type != null) { if (type.startsWith("text/")) { handleSendText(intent); // Handle text being sent } else if (type.startsWith("image/")) { handleSendImage(intent); // Handle single image being sent } } else if (android.content.Intent.ACTION_SEND_MULTIPLE === action && type != null) { if (type.startsWith("image/")) { handleSendMultipleImages(intent); // Handle multiple images being sent } } else { // Handle other intents, such as being started from the home screen } });

Nick Iliev
- 9,610
- 3
- 35
- 89
-
1Thanks. I think hardest part is iOS. I will try the today app example on NativeScript blog. But i also want to use Angular. I don’t know if two different angular apps are possible in same project. – zarax Sep 20 '18 at 12:05
-
Hi, What about the iOS part because I didn't find any example/tutorials for NativeScript, anyone found a way ? – noam aghai Nov 18 '18 at 09:13
-
On iOS, the above scenario is more complicated as it would require to enable the Share Extension in your iOS application. Currently, app extensions are not officially supported in NativeScript but you could still see how to enable them here https://github.com/NativeScript/nativescript-cli/issues/3965 and here https://www.nativescript.org/blog/making-a-today-widget-in-ios-with-nativescript-and-ui-for-nativescript – Nick Iliev Nov 19 '18 at 12:42
-
More about the native iOS Share extension here https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/Share.html – Nick Iliev Nov 19 '18 at 12:43