Android Augmented Reality
- by Azooz Totti
I'm working on my first Android Augmented Reality application. The application works pretty good if the ARActivity runs as the first class (android.intent.category.LAUNCHER) in the manifest file. But when I added a splash screen which means the ARActivity will be the second to run(android.intent.category.DEFAULT), the camera seems not detecting the marker. I believe the problem is all in the manifest file. Any suggestions ? Thanks
This is the manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ar.armarkers"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ar.armarkers.MainActivity"
android:clearTaskOnLaunch="true"
android:label="@string/title_activity_main"
android:noHistory="true"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="com.ar.armarkers.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
import edu.dhbw.andar.ARObject;
import edu.dhbw.andar.ARToolkit;
import edu.dhbw.andar.AndARActivity;
import edu.dhbw.andar.exceptions.AndARException;
import edu.dhbw.andar.pub.CustomRenderer;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AndARActivity {
private ARObject someObject;
private ARToolkit artoolkit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CustomRenderer renderer = new CustomRenderer();
setNonARRenderer(renderer);
try {
artoolkit = getArtoolkit();
someObject = new CustomObject1("test", "marker16.pat", 80.0,
new double[] { 0, 0 });
artoolkit.registerARObject(someObject);
someObject = new CustomObject2
("test", "marker17.patt", 80.0, new
double[]{0,0});
artoolkit.registerARObject(someObject);
} catch (AndARException ex) {
System.out.println("");
}
startPreview();
}
public void uncaughtException(Thread thread, Throwable ex) {
// TODO Auto-generated method stub
Log.e("AndAR EXCEPTION", ex.getMessage());
finish();
}
}
Splash.java
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread() {
public void run() {
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent i = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(i);
}
}
};
timer.start();
}
}