是否可以将文本,图像和文件共享到使用Nativescript编写的Android或iOS应用中?

时间:2018-09-17 17:48:38

标签: nativescript nativescript-plugin

我希望我的应用程序可以在其他应用程序的共享选项中列出,以便可以接收文本,图像或文件。是否可以使用Nativescript做到这一点?如果可以,怎么办?

1 个答案:

答案 0 :(得分:2)

这里是a POC demo app,它演示了如何使用NativeScript在Android上实现上述功能。只是as in native Android我将覆盖Activity onCreate方法并提供意图逻辑。

  • intent filters are added in AdnroidManifest.xml

  • 然后onCreate方法将被覆盖

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