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

标签 java ios iphone libgdx robovm

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

enter image description here

最佳答案

对于 iOS 用户:

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

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

要共享文本、图像和应用,您可以执行以下代码,

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

安卓用户:Sharing Content with intents

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

关于java - 如何使用 robovm (libgdx) 添加共享意图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33206825/

相关文章:

java - 在java中迭代期间存储多个匹配项

ios - 我如何在 XCode 4 (iOS) 中使用 EXCLUDED_SOURCE_FILE_NAMES

ios - 如何通过动画同时增加单元格高度和 subview 高度?

iphone - 在 iOS 5.0 中使用 ffmpeg 和 OpenGL 反转 Logo 和字幕

iphone - 可以使用iPhone进行编程吗?

iphone - 如何将 UITableViewController 中选定行的数量传递/发送到另一个类?

Java:沿圆形路径移动标签

java - 线程 "main"java.lang.NoClassDefFoundError : Running a package 中出现异常

java - 查询mongo中的列表

iphone - 同一库的重复符号 XCode 重复库?