如何使用robovm(libgdx)添加共享意图? [英] How to add a share intent with robovm (libgdx)?

查看:56
本文介绍了如何使用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,而Google Play服务则用于Android.不同的设备,不同的代码.对于android,将android sdk集成到您的IDE后,只需将google play服务库链接到android项目即可.

So for android devices there is a default share intent function that you call that will list all the apps that is downloaded on the device with that allows sharing of content. How would I do this using robovm, here is a Screen shot of what I am trying to achieve. Also on a side note, what I want to ultimately do is take a screenshot of their device and post it to whatever social media site the user chooses. Any help would be greatly appreciated :D

解决方案

For iOS users:

RoboVM is deprecated in favor of RoboPods. So, RoboVM is no more, what now?

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

For sharing text using roboVM, you can set the UIAvtivityViewController class

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

For sharing text, image and app, you can do the following code,

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

The following code sends an animated .gif through Mail and Messenger, however, Twitter only shares a static image.

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

For generic share in iOS, with text, link and image the code is given below:

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


For Android users: Sharing Content with intents

It says RoboVM is for iOS only, So how would we use it for android using LibGDX? roboVM with RoboPods is used for iOS while google play services is used for android. Different devices, different code. For android, after integrating the android sdk to your IDE, just link the google play services lib to the android project.

这篇关于如何使用robovm(libgdx)添加共享意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆