Android Development

Android Studio on Linux with the Hello Example

 

On old Mandriva Linux and NetBeans IDE 8.0 I could write simple apps to my old Android 2.x/4.x, just the Android tools and SDK needed, - and maybe that works nowadays too, - but it was easier to setup the necessary environment to Mageia Linux 9 by installing Android Studio.

Download the Android Studio from:
https://developer.android.com/studio

I've installed as root: (maybe needs this privileg for updating too)

I had got a tgz file and extracted to /usr/local folder with the following command:

tar -xf android-studio-2022.3.1.19-linux.tar.gz -C /usr/local

Run and configure at first time as user:

/usr/local/android-studio/bin/studio.sh &

 

So I've started to create my Android app for this website.

 

libGDX

libGDX - Android Studio - sample game on Linux and on Android emulator

 

There are so many cross-platform development possibilities, I've just tried libGDX.

As their websites sais (https://libgdx.com/wiki/start/project-generation), there is a multiplatform empty-project generator and e.g. Android Studio can open this generated project.

I found their sample game's code there and added to this empty project to try it. (have to download free pictures and sound files too) After some changes in configuration I can run it on my Mageia Linux 9 and on Android Emulator too at the same time. I also connected my old Sony mobile and it works well on it too. And it works on a local webserver too.

 

A short example: developing for multiple platforms with libGDX if you need different code. (this code opens my website in the default browser, for Android & Linux)

core/main/java/eu.tothpal.www/MyWebsite.java:

package eu.tothpal.www;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.utils.ScreenUtils;

public class MyWebsite extends ApplicationAdapter {

	private HelperInterface myHelper = null;

	public MyWebsite( HelperInterface H) {
		myHelper = H;
	}

	@Override
	public void create () {
		myHelper.OpenURLinDefaultBowser("http://www.tothpal.eu");
	}

	@Override
	public void render () {
		ScreenUtils.clear(0.05f, 0.05f, 0.4f, 1);
	}
	
	@Override
	public void dispose () {
	}
}

core/main/java/eu.tothpal.www/HelperInterface.java:

package eu.tothpal.www;

public interface HelperInterface {

    public void OpenURLinDefaultBowser( String url );
}

android/main/java/eu.tothpal.www/AndroidHelper.java:

package eu.tothpal.www;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class AndroidHelper implements HelperInterface {

    private Context context = null;

    public AndroidHelper(Context c ) {
        context = c;
    };

    public void OpenURLinDefaultBowser(String url) {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        context.startActivity(browserIntent);
    }
}

desktop/main/java/eu.tothpal.www/DesktopHelper.java:

package eu.tothpal.www;

import java.io.IOException;

public class DesktopHelper implements HelperInterface {

    public void OpenURLinDefaultBowser( String url ) {
		Runtime r = Runtime.getRuntime();
		try {
			r.exec("xdg-open "+url);
		}
		catch (IOException e) {};
    }
}

So you just have to initialize the correct Helper class in the AndroidLauncher and DesktopLauncher classes and later the Helper class can solve your problem...

Visitcount (since 2021-05-30): 0206