Android Intent and startActivity in Libgdx (non Activity or AndroidApplication class)(Libgdx 中的 Android Intent 和 startActivity(非 Activity 或 AndroidApplication 类))
问题描述
请帮助我如何在 Libgdx 线程中运行以下代码 - 在 render()、create() 等...
Please help me how to run the below code in Libgdx thread - in render(),create(),etc...
public class MyGame implements ApplicationListener, InputProcessor {
...
Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
.....
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"http://market.android.com/details?id=" + getPackageName()));
startActivity(marketIntent);
代码有编译错误.我搜索了一些类似的线程,但没有startActivity"的确切代码示例.谢谢.
The code has compilation errors. I googled some similar threads, but no exact code examples with "startActivity". Thanks.
推荐答案
LibGDX 是一个平台无关的库,所以所有使用 LibGDX 平台网络 API 的代码本身必须是平台无关的(所以没有 Android 或 Windows 调用等).要访问特定于平台的功能,标准方法是定义一个接口,并使用与平台无关的代码中的接口.然后在您的应用程序的 Android(或桌面)特定项目中创建接口的实现,并在初始化 libGDX 组件时传递该实现.
LibGDX is a platform independent library, so all the code that uses the LibGDX platform netural APIs must itself be platform independent (so no Android, or Windows calls, etc). To access platform-specific features, the standard way is to define an interface, and use the interface from your platform-neutral code. Then create an implementation of the interface in the Android (or Desktop) specific projects for your application, and pass that implementation when you initialize your libGDX component.
本教程有更多详细信息:http://code.google.com/p/libgdx-users/wiki/IntegratingAndroidNativeUiElements3TierProjectSetup
This tutorial has more details: http://code.google.com/p/libgdx-users/wiki/IntegratingAndroidNativeUiElements3TierProjectSetup
这是对相同方法的另一种描述(写得更好,但该示例与您的相关性不那么明显):https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code
Here's another description of the same approach (its better written, but the example isn't as clearly relevant to you): https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code
本教程对访问Android原生UI元素感兴趣,但基本思路和你想要的一样.
The tutorial is interested in accessing Android native UI elements, but the basic idea is the same as what you want.
这篇关于Libgdx 中的 Android Intent 和 startActivity(非 Activity 或 AndroidApplication 类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Libgdx 中的 Android Intent 和 startActivity(非 Activity 或


- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01