Android intent and startactivity in libgdx (non activity or androidapplication class)
Please help me how to run the following code in the 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);
There is a compilation error in the code. I searched some similar threads, but there is no exact code example of "startactivity". Thank you
resolvent:
Libgdx is a platform independent library. Therefore, all codes using libgdx platform netural API must be platform independent (so there are no android or windows calls). To access platform specific functions, the standard method is to define interfaces and use interfaces in platform independent codes. Then, create interface implementations in Android (or desktop) specific projects of applications, And pass the implementation when initializing the libgdx component
This tutorial has more details: http://code.google.com/p/libgdx-users/wiki/IntegratingAndroidNativeUiElements3TierProjectSetup
This is another description of the same method (it is better written, but this example is not as clear as you): http://code.google.com/p/libgdx/wiki/ApplicationPlatformSpecific
This tutorial is interested in accessing Android native UI elements, but the basic idea is the same as you want
Another tutorial: https://carlorodriguez.github.io/blog/2014/10/05/android-platform-specific-code-with-libgdx/