繁体   English   中英

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

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

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

在此输入图像描述

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

对于共享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用户: 使用意图共享内容

它说RoboVM仅适用于iOS,那么我们如何使用LibGDX将它用于Android呢? 带有RoboPods的roboVM用于iOS,而谷歌播放服务用于Android。 不同的设备,不同的代码。 对于android,在将android sdk集成到你的IDE后,只需将google play服务lib链接到android项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM