Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:01:15+00:00 2026-05-27T11:01:15+00:00

I am trying to Develop a Light Sensor App for my LG P990 to

  • 0

I am trying to Develop a Light Sensor App for my LG P990 to detect a Laser (don’t ask why).

The Code looks like this:

package soma.de.Light;

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.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class LightSensorActivity extends Activity {

 SensorManager mySensorManager;
 Sensor myLightSensor;
 TextView textLightSensorData;
 TextView textLightSensor;

Button Start;


public void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   textLightSensor = (TextView)findViewById(R.id.tvLight);
   textLightSensorData = (TextView)findViewById(R.id.tvAcc);

   mySensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
   myLightSensor = mySensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

   Start = (Button)findViewById(R.id.btStart);
   Start.setOnClickListener(btListener);    

   if (myLightSensor == null){
    textLightSensor.setText("No Light Sensor!"); //THIS IS WHAT I GET!
   }else{
    textLightSensor.setText(myLightSensor.getName() + "\n " + myLightSensor.getResolution()  );

    mySensorManager.registerListener(lightSensorEventListener,
      myLightSensor,
      SensorManager.SENSOR_DELAY_NORMAL);
   }
}

private OnClickListener btListener = new OnClickListener()
{
public void onClick(View v){                 
    myLightSensor = mySensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);    
    if (myLightSensor == null){
        textLightSensor.setText("No Light Sensor!");
       }else{
        textLightSensor.setText(myLightSensor.getName() + "\n " + myLightSensor.getResolution()      );

        mySensorManager.registerListener(lightSensorEventListener,
          myLightSensor,
          SensorManager.SENSOR_DELAY_NORMAL);
       }
}
};

SensorEventListener lightSensorEventListener
 = new SensorEventListener(){

@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
 // TODO Auto-generated method stub

}

@Override
public void onSensorChanged(SensorEvent arg0) {
 // TODO Auto-generated method stub
 if(arg0.sensor.getType()==Sensor.TYPE_LIGHT){
 textLightSensorData.setText("Light Sensor Date:"
   + String.valueOf(arg0.values[0]));
}else if(arg0.sensor.getType()==Sensor.TYPE_PROXIMITY){
 textLightSensorData.setText("Test "
   + String.valueOf(arg0.values[0]) +" " +  String.valueOf(arg0.values[1]));
}
}};
}

But I only get a “No Light Sensor” return on my Activity.
The LG P990 does have one. In the “hidden menu” I can see the values of the light Sensor in the ALC / Proximity Test.

Do I have to change anything in my code to get it to run?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:01:15+00:00Added an answer on May 27, 2026 at 11:01 am

    not sure about getDefaultSensor(), but the documentation for it says:

        Note that the returned sensor could be a composite sensor,
        and its data could be averaged or filtered. If you need to access
        the raw sensors, use getSensorList()
    

    This is how I’m doing it:

        SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    
        // Check if there is at least one light sensor
        if (sm.getSensorList(Sensor.TYPE_LIGHT).size() == 0) {
            // No light sensor installed
        }
        else {
            Sensor light = sm.getSensorList(Sensor.TYPE_LIGHT).get(0);
            if (!sm.registerListener(this, light, SensorManager.SENSOR_DELAY_GAME)) {
                // Couldn't register light sensor listener
            }
        }
    

    And then in your onSensorChanged() method, event.values[0] gives you the value of the light sensor, that is an integer in the 0..100 range, even if I have only seen values of 10 and 100 🙂

    Good luck,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to develop an XSD for some XML that looks roughly like
I'm trying to develop code for mpeg/h.264/RTP streaming. I'm quite new to all this
Im trying to develop my first ASP.NET MVC web app and have run into
I am trying develop an Android app which uses Google maps. So for the
I am trying to develop a multi-screen app for the Google TV platform using
I have been trying to develop an app for my ipad which i can
Trying to develop using MVVM: I have this Csla.PropertyStatus control that is created in
I am trying develop an application (C#) to query an LDAP server. I don't
I'd been trying to develop one with this for a long time. I'd try
I am trying to develop a mobile app, that registered with a Java program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.