简体   繁体   中英

Android development with sensor accelerometer and brightness

I'm developing an app that uses the sensor accelerometer. I want the display to go black for instance when a value reach 8.1 and go back to normal when 7 is reached. Is it possible without using screen brightness? I want it to be complete black and this is not possible what i know with screen brightness.

Hope I gave enough information.

Try this in your activity. Let your main.xml load a black image -

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

Since you also need the screen to be black while you are using other apps. Then you need to write a background service that receives the accelerometer values and when it reaches 8.1, you can use the above snippet of code in your service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM