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