Libgdx 中的 Android Intent 和 startActivity(非 Activity 或 AndroidApplication 类) [英] Android Intent and startActivity in Libgdx (non Activity or AndroidApplication class)

查看:16
本文介绍了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 类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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