So I'm following the book Open GL ES 2 for Android by Kevin Brothaler and I'm trying out the first chapter's project, which is basically coloring the screen red. I set up by Samsung Galaxy Note 3 so I can debug my app on there, and also set up an emulator that uses the host GPU for rendering. Also, I forced GPU rendering on my phone. I copied the code he had exactly into my eclipse project. Here's the code for reference:
package com.firstopenglproject.android;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;
//import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class FirstOpenGLProjectActivity extends Activity {
private static final String TAG = FirstOpenGLProjectActivity.class.getSimpleName();
private GLSurfaceView glSurfaceView;
private boolean rendererSet = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "Before calling super.onCreate()");
super.onCreate(savedInstanceState);
Log.d(TAG, "Before creating a new GLSurfaceView");
glSurfaceView = new GLSurfaceView(this);
Log.d(TAG, "Creating activity manager");
final ActivityManager activityManager =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
Log.d(TAG, "Creating configuration info");
final ConfigurationInfo configurationInfo =
activityManager.getDeviceConfigurationInfo();
Log.d(TAG, "Getting supportsEs2 boolean");
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
// || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
// && (Build.FINGERPRINT.startsWith("generic")
// || Build.FINGERPRINT.startsWith("unknown")
// || Build.MODEL.contains("google_sdk")
// || Build.MODEL.contains("Emulator")
// || Build.MODEL.contains("Android SDK built for x86")));
Log.d(TAG, "supportsEs2 = " + supportsEs2);
if (supportsEs2) {
// Request an OpenGLES2 compatible context
glSurfaceView.setEGLContextClientVersion(2);
glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
// Assign our renderer
glSurfaceView.setRenderer(new FirstOpenGLProjectRenderer());
rendererSet = true;
Toast.makeText(this, "Device supports OpenGL ES 2.0", Toast.LENGTH_LONG).show();
Log.d(TAG, "rendererSet is true");
} else {
Log.d(TAG, "OGLES2.0 not supported");
Toast.makeText(this, "This device does not support OpenGL ES 2.0", Toast.LENGTH_LONG).show();
return;
}
}
#Override
protected void onPause() {
super.onPause();
if (rendererSet) {
glSurfaceView.onPause();
}
}
#Override
protected void onResume() {
super.onResume();
if (rendererSet) {
glSurfaceView.onResume();
}
}
}
The logging tasks were ones that I added so that I can see whether the code is executing properly, and it is: I see all these log messages in LogCat. Here's the code for the renderer:
package com.firstopenglproject.android;
import static android.opengl.GLES20.GL_COLOR_BUFFER_BIT;
import static android.opengl.GLES20.glClear;
import static android.opengl.GLES20.glClearColor;
import static android.opengl.GLES20.glViewport;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView.Renderer;
public class FirstOpenGLProjectRenderer implements Renderer {
private static final String TAG = FirstOpenGLProjectRenderer.class.getSimpleName();
/*
* GLSurfaceView calls this when its time to draw a frame. We must
* draw something, even if its only to clear the screen. The rendering buffer
* will be swapped and displayed on the screen after this method returns,
* so if we don't draw anything, we'll probably get a bad flickering effect.
* */
#Override
public void onDrawFrame(GL10 arg0) {
// clear the rendering surface
glClear(GL_COLOR_BUFFER_BIT);
}
/*
* GLSurfaceView calls this after the surface is created and whenever the size has
* changed. A size change can occur when switcheing from portrait to landscape
* and vice versa.
*/
#Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
// set the openGL viewport to fill the entire surface
glViewport(0, 0, width, height);
}
/*
* GLSurfaceView calls this when the surface is created. This happens the first
* time our application is run, and it may also be called when the device wakes
* up or when the user switches back to our activity. In practice, this means that
* this method may be called multiple times while our application is still running.
*/
#Override
public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) {
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
}
}
As you can see, I only use 3 calls to static methods in the GLES20 package. When I run this app on my phone and on my emulator I get a blank screen: what is going on? I've been banging my head on the table for the last 2 hours about this, and this is as simple as it could possibly get. It's supposed to display a red screen. Thanks a bunch!
you are not setting the view in your OnCreate() method at the end of that method add:
setContentView(glSurfaceView);
Related
I bought myself a android car unit and came at the conclusion that the minimum brightness is still to bright when driving in the night. There is a clever app called screen filter that (i think it works like this) uses a overlay over the screen to fake a screen dimming. I wanted to make this by myself because i want to enable it when it's sunset and disable it after sunrise.
After some searching in the web i found a usable code.
Create a Main activity with a service called Overlayservice. The service runs when i start the app and the overlay also works fine.
The next thing i want to make is a code so i can change the overlay transparency. I want that the program starts fading when sunset starts and for example after an half hour the transparency is 50%.
The problem i am facing at is i am not able to set a new colour and transparency while the overlay is active in a service.
What i tired was creating a timer in the service that sets the colour after 5 seconds but i got a crash with the error:
Only the original thread that created a view hierarchy can touch its views.
The code i now have is as following:
package erik.autostart;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.LinearLayout;
import java.util.Timer;
import java.util.TimerTask;
public class OverlayService extends Service {
String color;
LinearLayout oView;
WindowManager.LayoutParams localLayoutParams;
private static Timer timer = new Timer();
#Override
public IBinder onBind(Intent i) {
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
this.color = intent.getExtras().getString("color");
Log.v("Message","Intent: " + Color.parseColor(this.color));
oView = new LinearLayout(getBaseContext());
localLayoutParams = new WindowManager.LayoutParams();
oView.setBackgroundColor(Color.parseColor(this.color)); //De eerste 2 waardes zijn de density ff is volledig en 00 is weg de laatste 6 waardes zijn hex color waardes, kan dus zwart zijn.
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
WindowManager manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.format = PixelFormat.TRANSLUCENT;
manager.addView(oView, localLayoutParams);
timer.scheduleAtFixedRate(new Task(), 0, 500);
return START_STICKY;
}
private class Task extends TimerTask
{
public void run()
{
Log.v("Message", "Tasker");
runtask();
}
}
void runtask()
{
if(oView!=null){
oView.setBackgroundColor(Color.parseColor("#ff000000"));
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.updateViewLayout(oView, oView.getLayoutParams());
}
}
#Override
public void onCreate() {
super.onCreate();
Log.v("Message", "OverlayService started");
}
#Override
public void onDestroy() {
if(oView!=null){
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.removeView(oView);
}
Log.v("Message", "Destroying OverlayService");
super.onDestroy();
}
}
I want to run a tasker somewhere so i can set the new colour and update the overlay.
To fix this i thought perhaps stopping the service and starting it again with a new colour would help so i made a taker in the Mainactivity and stopped the service and start a new one with a different colour. The problem there is that the screen flickers.
I was hoping someone can help me with this problem. Is it even possible to do what i want?
The complete answer I promised earlier. I'm sorry for the untested code, I haven't done anything with Android development in about half a year and don't have the setup ready to test code.
That said, probably the best way is to use Handler. The Handler is initialized to be run on the main (UI) thread, so that it can modify UI. The Dimmer executes on the UI thread, thus preventing the problem you had.
...
public class OverlayService extends Service {
Handler handler;
...
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
...
manager.addView(oView, localLayoutParams);
handler.postDelayed(new Dimmer("#ff000000"), 500);
return START_STICKY;
}
private class Dimmer implements Runnable {
private String color;
public Dimmer (String color) {
this.color = color;
}
public void run() {
if(oView!=null){
oView.setBackgroundColor(Color.parseColor(color));
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.updateViewLayout(oView, oView.getLayoutParams());
}
}
}
#Override
public void onCreate() {
super.onCreate();
Log.v("Message", "OverlayService started");
handler = new Handler(Looper.getMainLooper());
}
...
}
I'm having some problems with creating a SensorManager and outputting the values of the accelerometer on the screen with a green circle that moves when you tilt the phone. It's an example from Sam's teach yourself android game programming in 24 hours by Jonathan Harbour. I have checked and double checked and my code is identical to his. Basically, it's a Custom SurfaceHolder canvas that uses a Thread to repeatedly update. Here is the main activity, Game (yes, I know, the imports are messy):
package com.example.sensordemo;
import java.util.*;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.AssetManager;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.renderscript.Float2;
import android.renderscript.Float3;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
public class Game extends Activity implements SensorEventListener
{
DrawView drawView;
SensorManager sensors;
Sensor accel;
Float3 accelMotion = new Float3();
List<Sensor> sensorList;
#Override public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
drawView = new DrawView(this);
setContentView(drawView);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
sensors = (SensorManager) getSystemService(SENSOR_SERVICE);
accel = sensors.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorList = sensors.getSensorList(Sensor.TYPE_ALL);
Log.i("Game", "onCreate()");
}
#Override public void onSensorChanged(SensorEvent event)
{
switch (event.sensor.getType())
{
case Sensor.TYPE_ACCELEROMETER:
accelMotion.x = event.values[0];
accelMotion.y = event.values[1];
accelMotion.z = event.values[2];
break;
}
}
#Override public void onAccuracyChanged(Sensor arg0, int arg1)
{
}
#Override public void onResume()
{
super.onResume();
Log.i("Game", "resume");
drawView.resume();
sensors.registerListener(this, accel, SensorManager.SENSOR_DELAY_NORMAL);
}
#Override public void onPause()
{
super.onPause();
drawView.pause();
sensors.unregisterListener(this);
Log.i("Game", "pause");
}
public class DrawView extends SurfaceView implements Runnable
{
Thread gameloop = null;
SurfaceHolder surface = null;
volatile boolean running = false;
AssetManager assets = null;
Paint paint = new Paint();
Float2 center;
public DrawView(Context context)
{
super(context);
surface = getHolder();
assets = context.getAssets();
Log.i("Game", "draw view made");
}
public void resume()
{
running = true;
gameloop = new Thread(this);
gameloop.start();
Log.i("Game", "drawview resumed");
}
public void pause()
{
running = false;
Log.i("DrawView", "pausing");
while(true)
{
try
{
gameloop.join();
}
catch(InterruptedException e)
{
}
}
}
#Override public void run()
{
while(running)
{
if(!surface.getSurface().isValid()) continue;
Canvas canvas = surface.lockCanvas();
canvas.drawColor(Color.BLACK);
Log.i("Game", "running");
float width = canvas.getWidth();
float height = canvas.getHeight();
center = new Float2(width / 2.0f, height / 2.0f);
Float2 ratio = new Float2(width / 10.0f, height / 10.0f);
float x = center.x - accelMotion.x * ratio.x;
float y = center.y + accelMotion.y * ratio.y;
paint.setColor(Color.GREEN);
canvas.drawCircle(x, y, 100, paint);
paint.setColor(Color.WHITE);
paint.setTextSize(24);
canvas.drawText("Accelerometer Demo", 10, 20, paint);
String s = "X=" + Math.round(accelMotion.x) + ", Y=" + accelMotion.y + ", Z=" + accelMotion.z;
canvas.drawText(s, 10, 50, paint);
canvas.drawText("Model: " + accel.getVendor(), 10, 80, paint);
surface.unlockCanvasAndPost(canvas);
try
{
Thread.sleep(20);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}
I don't know what the problem is. The Screen goes all white and nothing happens (The thingy at the top with notifications is still visible). Also, it crashes the phone sometimes. It's a htc 1 M7 running android 5.0.1. This is the output from Logcat:
06-17 21:47:40.760: W/asset(14951): Copying FileAsset 0xb85d1e68 (zip:/data/app/com.example.sensordemo-1/base.apk:/resources.arsc) to buffer size 157568 to make it aligned.
06-17 21:47:40.770: E/Typeface(14951): SANS_LOC file not found.
06-17 21:47:40.790: I/Game(14951): draw view made
06-17 21:47:41.090: E/SensorManager(14951): uid = 10196
06-17 21:47:41.100: E/SensorManager(14951): uid = 10196
06-17 21:47:41.100: I/Game(14951): onCreate()
06-17 21:47:41.110: I/Game(14951): resume
06-17 21:47:41.110: I/Game(14951): drawview resumed
06-17 21:47:41.110: I/SensorManager(14951): registerListenerImpl: listener = com.example.sensordemo.Game#110bc638, sensor = {Sensor name="BOSCH BMA250 3-axis Accelerometer", vendor="BOSCH", version=1, type=1, maxRange=39.2266, resolution=0.038307227, power=0.1, minDelay=10000}, delay = 200000, handler = null
06-17 21:47:41.130: D/Atlas(14951): Validating map...
06-17 21:47:41.150: E/Typeface(14951): SANS_LOC file not found.
06-17 21:47:41.150: I/DrawView(14951): pausing
I would just like to note that pause is called straight away, not when I tab out of the app. Exiting and entering the app does not make the programme continue, it just stops. Nothing happens on the screen apart from it turning white, going into landscape mode and nothing else. Sorry for the long post, but I have no idea what is going on, and so I have tried to include all relevant sources. Any suggestions, ideas and, of course, any solutions you have please comment or reply below. All help is appreciated. If you require any other files I will add them, just tell me.
I'm working with the same book and had the same problem... ran across your question looking for an answer, so I thought I'd backtrack and pass along what I found (after MUCH pain and suffering lol)
The problem seems to be in the pause procedure (not the onPause, the pause in DrawView). I think it was that the thread was not properly stopped, and they tried to re-start the same thread again in the resume procedure.
After changing it to the following code, everything seems to work fine.
public void pause() {
gameloop.interrupt();
running = false;
try{
gameloop.join();
} catch (InterruptedException e) {}
}
This is my Demo program while learning opengl in android development
it shows NullPointerException Fatal exception Runtime exceptojection etc... help me in resolving this problem I am sending 2 java files...which are only files i have modified in an android application project....
FirstOpenGLProjectActivity.java
package com.example.firstopenglproject;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import android.widget.Toast;
public class FirstOpenGLProjectActivity extends Activity {
/**
* Hold a reference to our GLSurfaceView
*/
private GLSurfaceView glSurfaceView;
private boolean rendererSet = false;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
glSurfaceView = new GLSurfaceView(this);
// Check if the system supports OpenGL ES 2.0.
final ActivityManager activityManager =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo =
activityManager.getDeviceConfigurationInfo();
/*
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
*/
// Even though the latest emulator supports OpenGL ES 2.0,
// it has a bug where it doesn't set the reqGlEsVersion so
// the above check doesn't work. The below will detect if the
// app is running on an emulator, and assume that it supports
// OpenGL ES 2.0.
final boolean supportsEs2 =
configurationInfo.reqGlEsVersion >= 0x20000
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
&& (Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.startsWith("unknown")
|| Build.MODEL.contains("google_sdk")
|| Build.MODEL.contains("Emulator")
|| Build.MODEL.contains("Android SDK built for x86")));
if (supportsEs2) {
// Request an OpenGL ES 2.0 compatible context.
glSurfaceView.setEGLContextClientVersion(2);
// Assign our renderer.
glSurfaceView.setRenderer(new FirstOpenGLProjectRenderer());
rendererSet = true;
} else {
/*
* This is where you could create an OpenGL ES 1.x compatible
* renderer if you wanted to support both ES 1 and ES 2. Since we're
* not doing anything, the app will crash if the device doesn't
* support OpenGL ES 2.0. If we publish on the market, we should
* also add the following to AndroidManifest.xml:
*
* <uses-feature android:glEsVersion="0x00020000"
* android:required="true" />
*
* This hides our app from those devices which don't support OpenGL
* ES 2.0.
*/
Toast.makeText(this, "This device does not support OpenGL ES 2.0.",
Toast.LENGTH_LONG).show();
return;
}
setContentView(glSurfaceView);
}
#Override
protected void onPause() {
super.onPause();
if (rendererSet) {
glSurfaceView.onPause();
}
}
#Override
protected void onResume() {
super.onResume();
if (rendererSet) {
glSurfaceView.onResume();
}
}
}
other file is FirstOpenGLProjectRenderer.java
package com.example.firstopenglproject;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView.Renderer;
public class FirstOpenGLProjectRenderer implements Renderer
{
private static final String GL_COLOR_BUFFER_BIT = null;
#Override
public void onDrawFrame(GL10 glUnused) {
// Clear the rendering surface.
glClear(GL_COLOR_BUFFER_BIT);
}
private void glClear(String glColorBufferBit) {
// TODO Auto-generated method stub
}
#Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
// Set the OpenGL viewport to fill the entire surface.
glViewport(0, 0, width, height);
}
private void glViewport(int i, int j, int width, int height) {
// TODO Auto-generated method stub
}
#Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
}
private void glClearColor(float f, float g, float h, float i) {
// TODO Auto-generated method stub
}
}
when I create a new android application project this is the same problem I face each and every time can anyone suggest me to solve this "FATAL EXCEPTION","NullPointerException" problem....
do i Need to reinstall all eclipse...sdk...?
Why is this line present ? GL_COLOR_BUFFER_BIT is a GL defined macro and has a specific value in GL and you cannot override with NULL. Remove it and try again.
private static final String GL_COLOR_BUFFER_BIT = null;
I just started learning how to program for android and cant seem to get the x positions for when someone clicks on the screen to appear in log cat. (im using an emulator if that has to do with anything) when i do click on the screen nothing happens. Here is my program on startup i get no errors. also using a relative layout
package com.practice;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class PracticeActivity extends Activity implements OnTouchListener{
int touchX;
int touchY;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onTouch(View v, MotionEvent event) {
onTouchEvent(event);
touchX = (int) event.getX();
touchY = (int) event.getY();
Log.d( "MOUSE", String.valueOf(touchX) );
return true;
}
}
Your OnTouchListener won't get called until you register it with a view. For example:
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Find a view in the layout
View view = findViewById(android.id.content);
// register the listener
view.setOnTouchListener(this);
}
Try using Integer.toString(touchX) and return false instead of true, other than that your code seems fine.
Emulator do register the touch events.
Also there is a utility called as DDMS, located in the tools folder of the SDK. When your emulator is running, use this utility to get the graphical logcat. You can filter messages as well.
alright so I'm new to programming for android, and I think I did something wrong, but I don't know what. I've looked at 3 different tutorials and my code seems to look like theirs. Can anyone tell me what I'm doing wrong? here is my src (altered from a android nehe tutorial).
package cypri.games;
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
/**
* The initial Android Activity, setting and initiating
* the OpenGL ES Renderer Class #see Lesson02.java
*
* #author Savas Ziplies (nea/INsanityDesign)
*/
public class DGearActivity extends Activity {
/** The OpenGL View */
private GLSurfaceView glSurface;
DGear dGear = new DGear();
private static final String TAG = "DEBUG";
SensorManager sensorManager;
private final SensorEventListener sensorListener = new SensorEventListener(){
public void onSensorChanged(SensorEvent se) {
if (se.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
dGear.playerX = se.values[0];
Log.v(TAG, "se.values[0] =" + se.values[0]);
}
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
/**
* Initiate the OpenGL View and set our own
* Renderer (#see Lesson02.java)
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
//Create an Instance with this Activity
glSurface = new GLSurfaceView(this);
//Set our own Renderer
glSurface.setRenderer(dGear);
//Set the GLSurface as View to this Activity
setContentView(glSurface);
}
/**
* Remember to resume the glSurface
*/
#Override
protected void onResume() {
Log.v(TAG, "or");
super.onResume();
glSurface.onResume();
sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
}
/**
* Also pause the glSurface
*/
#Override
protected void onPause() {
super.onPause();
glSurface.onPause();
Log.v(TAG, "op");
sensorManager.unregisterListener(sensorListener);
}
}
Are you running this in the emulator or on an actual device?
If you're running it on an actual device are you sure it has a gyroscope? There are lots of different sensor types and the gyroscope is only one of them. It could very well be one of the others.
Instead of only writing to the log if it's a gyroscope type, try writing the name of the se.sensor when that event fires. That way you'll at least know the event is firing.