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

Java 如何使用robovm(libgdx)添加共享意向?,java,ios,iphone,libgdx,robovm,Java,Ios,Iphone,Libgdx,Robovm,因此,对于android设备,您可以调用一个默认的共享意图函数,该函数将列出设备上下载的所有允许共享内容的应用程序。我将如何使用robovm做到这一点,这里是我试图实现的屏幕截图。另一方面,我最终想做的是拍摄他们设备的屏幕截图,并将其发布到用户选择的任何社交媒体网站。任何帮助都将不胜感激 对于iOS用户: RoboVM被弃用,取而代之的是RoboPods。所以 要使用roboVM共享文本,可以设置UIAvtivityViewController类 NSString textShare = ne

因此,对于android设备,您可以调用一个默认的共享意图函数,该函数将列出设备上下载的所有允许共享内容的应用程序。我将如何使用robovm做到这一点,这里是我试图实现的屏幕截图。另一方面,我最终想做的是拍摄他们设备的屏幕截图,并将其发布到用户选择的任何社交媒体网站。任何帮助都将不胜感激

对于iOS用户: RoboVM被弃用,取而代之的是RoboPods。所以

要使用roboVM共享
文本
,可以设置
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);
要共享
文本、图像和应用程序
,您可以执行以下代码:

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); 
 }
对于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);
}
@覆盖
公开股{
NSArray项目=新NSArray(
新的NSString(“嘿!看看我用的这个疯狂的搜索引擎”),
新NSURL(“https://www.google.com"),
新UIImage(Gdx.files.external(“image.png”).file())
);
UIActivityViewController UIActivityViewController=新UIActivityViewController(项,空);
((IOSApplication)Gdx.app.getUIViewController().presentViewController(uiActivityViewController,true,null);
}

对于Android用户: 它说RoboVM只适用于iOS,那么我们如何使用LibGDX在android上使用它呢?
iOS使用带RoboPods的roboVM,android使用google play services。不同的设备,不同的代码。对于android,在将android sdk集成到IDE之后,只需将google play services库链接到android项目。

iOS部分在2019年仍然有效。对于Android,它不需要有播放服务。@MrStahlfelge。它可以工作,但是如果你尝试文本、链接和图像,你会得到不同的结果,这取决于平台。这不太好。。使用Instagram>仅显示图像而不显示文本。使用电子邮件>电子邮件+链接+文本。那很好。使用Whatsapp>Text+UR。使用Twitter>图像+文本。使用Facebook>仅链接,您知道如何在电子邮件中设置主题吗?
@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);
}