Skip to content

Hello World Android

mdelacalle edited this page Sep 8, 2014 · 1 revision

The code of this app can be found on: Hello World App Code Source

Create and android application

  • File -> new -> Android App Project
  • Using the wizard you'll have a project with the following aspect:

android project

  • Now you must add the G3M libraries to your project:
  • Right button over your project-> build path -> configure build path

android project

  • Click on Android and add the G3MAndroidSDK

android project

##Starting with the app

The Manifest file

Documentation about this file could be find here: Android Manifest File

For correct work of the g3m apps you must to put on manifest the following labels:

<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>  

And on the app label:
android:largeHeap="true"

Manifest Code

The Layout File

You can put the map wherever on the Android app, for example you can use a LinearLayout to put the map in:

With this code we will have a map in a complete screen, all this stuff is Android common code.
Layout Code

The Java Code

In the main activity of your android class:

public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

	final G3MBuilder_Android builder = new G3MBuilder_Android(this);
	
	G3MWidget_Android g3mWidget = builder.createWidget();

	 final LinearLayout layout = (LinearLayout) findViewById(R.id.glob3);
     layout.addView(g3mWidget);
	
}

You have to declare a Builder. G3M follow the design pattern Builder
Builder Pattern

After declare the builder , you can build the widget as you want (This is the minimal code) simply setting parameters.

Finally you create the Widget with --> builder.createWidget();

Finally you add the G3MWidget_Android (This object is an Android View) to your defined layout

The Java Class

Execute your app and you will have:

Simple Globe

Clone this wiki locally