如何使用 robovm (libgdx) 添加共享意图?

How to add a share intent with robovm (libgdx)?

因此,对于 android 设备,有一个您调用的默认共享意图函数,它将列出设备上下载的所有允许共享内容的应用程序。我将如何使用 robovm 执行此操作,这是我正在尝试实现的屏幕截图。另外在旁注中,我最终想做的是截取他们设备的屏幕截图,然后 post 将其发送到用户选择的任何社交媒体网站。任何帮助将不胜感激:D

iOS 用户:

RoboVM 已弃用,取而代之的是 RoboPods。所以,RoboVM is no more, what now?

https://github.com/robovm/robovm-robopods/tree/master

要使用 roboVM 共享 text,您可以设置 UIAvtivityViewController class

NSString textShare = new NSString("This is the text to share");
NSArray texttoshare = new NSArray(textShare);
UIActivityViewController share = new UIActivityViewController(texttoshare,null);
presentViewController(share, true, null);

为了分享text, image and app,可以做如下代码,

NSURL imgUrl = new NSURL(EXTERNAL_IMG_URL);
NSData data = NSData.read(imgUrl); 
UIImage image = new UIImage(data); 
NSString appStoreUrl = new NSString(APP_STORE_URL); 
NSString googleUrl = new NSString(GOOGLE_PLAY_URL); 
NSString text = new NSString(TEXT_TO_SHARE); 
NSArray<NSObject> texttoshare = new NSArray<NSObject>(text, image, appStoreUrl, googleUrl); 
UIActivityViewController share = new UIActivityViewController( 
texttoshare, null); 
if (UIDevice.getCurrentDevice().getUserInterfaceIdiom() == UIUserInterfaceIdiom.Phone) {  

 //iPhone 
iosApplication.getUIViewController().presentViewController( 
 share, true, null);  
} else { 
 //iPad 

 UIPopoverController popover = new UIPopoverController(share);
 UIView view = iosApplication.getUIViewController().getView(); 
 CGRect rect = new CGRect( 
 view.getFrame().getWidth() / 2, 
 view.getFrame().getHeight() / 4, 
 0, 
 0); 
 popover.presentFromRectInView( rect, view, UIPopoverArrowDirection.Any, true); 
 }

以下代码通过 Mail 和 Messenger 发送动画 .gif,但是 Twitter 仅共享静态图像。

public void shareGif(String path)
{        
    NSURL url = new NSURL(new File(path));

    NSArray<NSObject> imageArray = new NSArray<NSObject>(image);
    UIActivityViewController share = new UIActivityViewController(imageArray,null);
    ((IOSApplication)Gdx.app).getUIViewController().presentViewController(share, true, null);
}

对于 iOS 中的通用共享,text, link and image 代码如下:

@Override
public void share() {
    NSArray<NSObject> items = new NSArray<>(
            new NSString("Hey! Check out this mad search engine I use"),
            new NSURL("https://www.google.com"),
            new UIImage(Gdx.files.external("image.png").file())
    );
    UIActivityViewController uiActivityViewController = new UIActivityViewController(items, null);
    ((IOSApplication) Gdx.app).getUIViewController().presentViewController(uiActivityViewController, true, null);
}

Android 用户:Sharing Content with intents

它说 RoboVM 仅用于 iOS,那么我们如何将它用于 android 使用 LibGDX? 带有 RoboPods 的 roboVM 用于 iOS,而 google 播放服务用于 android。不同的设备,不同的代码。对于 android,在将 android sdk 集成到您的 IDE 之后,只需 link google 播放服务库到 android 项目。