Libgdx中的Android Intent和startActivity(非Activity或AndroidApplication类) [英] Android Intent and startActivity in Libgdx (non Activity or AndroidApplication class)
问题描述
请帮助我如何在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
这里是对相同方法的另一种描述(写得更好,但是该示例与您不太清楚):
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屋!