Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable accelerometer and simulate it with key inputs

I would like to create an android app that makes the user play games requiring to tilt the screen with key inputs. Is it possible to simulate accelerometer data when some key is pressed? In the meantime, can I disable with some code the real accelerometer when my app is running?

EDIT: I forgot to mention that I have access to the full android source, plus kernel source, so I could even add specific code or create some java code to disable or "fake" the source of accelerometer inputs.

like image 855
Vektor88 Avatar asked Jun 18 '26 07:06

Vektor88


1 Answers

By following this tutorial, you can disable Accelerometer easily.

Note the lines

package com.badlogic.drop;

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;

public class AndroidLauncher extends AndroidApplication {
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      AndroidApplicationConfiguration config= new AndroidApplicationConfiguration();
      config.useAccelerometer = false;
      config.useCompass = false;

      initialize(new Drop(), config);
   }
}

Thee tutorial in the link is for libgdx and libgdx is a Java game development framework that provides a unified API that works across all supported platforms including android.

like image 53
codeonion Avatar answered Jun 19 '26 19:06

codeonion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!