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

2022-09-03 14:58:20

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

enter image description here


答案 1

对于 iOS 用户:

RoboVM被弃用,取而代之的是RoboPods。那么,RoboVM已经不复存在了,现在该怎么办?

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

对于使用 roboVM 进行共享,您可以设置类textUIAvtivityViewController

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发送动画,但是,Twitter仅共享静态图像。.gif

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 用户:有意向地共享内容

它说RoboVM仅适用于iOS,那么我们如何将其用于使用LibGDX的Android?roboVM with RoboPods用于iOS,而Google Play服务用于Android。不同的设备,不同的代码。对于Android,将Android sdk集成到您的IDE之后,只需将Google Play服务lib链接到Android项目即可。


答案 2

推荐