如何在RoboVM(libgdx)中添加共享意图?

16

对于Android设备,有一个默认的共享意图函数,您可以调用该函数列出在设备上下载的所有应用程序,这些应用程序允许共享内容。如何使用robovm实现这一点,在此处是我尝试实现的截屏。此外,顺便说一句,我最终想做的是拍摄他们设备的屏幕截图,并将其发布到用户选择的任何社交媒体网站。非常感谢您的帮助:D

输入图像说明

1个回答

16

对于iOS用户:

RoboVM已被RoboPods取代。因此,RoboVM已不再使用,那么现在该怎么办呢?

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

如果想要使用roboVM分享text,可以设置UIAvtivityViewController类。

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

如果您想分享文本、图片和应用,可以使用以下代码:

// Code goes here
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); 
 }
以下代码可以通过邮件和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通用分享代码,包含文本、链接和图片

@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用户: 使用Intent分享内容

RoboVM只适用于iOS,那么我们如何在使用LibGDX时在Android上使用它呢?在iOS上,使用带有RoboPods的RoboVM,而在Android上使用Google Play服务。不同的设备需要不同的代码。对于Android,将Android SDK集成到您的IDE中后,只需将Google Play服务库链接到Android项目即可。


1
iOS部分在2019年仍然有效。对于Android,不需要安装Play服务。 - MrStahlfelge
@MrStahlfelge。它可以工作,但如果您尝试文本、链接和图像,则根据平台获得不同的结果。这不太好。 在Instagram上>只有图像没有文本。在电子邮件中>电子邮件+链接+文本。那很好。在WhatsApp中>文本+UR。在Twitter上>图像+文本。在Facebook上>只有链接。 - Julien
如何设置电子邮件主题? - Will Calderwood

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接