Is it possible to share text, image and file into an Android or iOS app written with Nativescript?

645 Views Asked by At

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?

1

There are 1 best solutions below

4
On

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.

  • The intent filters are added in AdnroidManifest.xml

  • 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
        }
    });