In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces Android how to achieve flashlight function, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
/ / Activity.xmlpackage com.fq.flashlight;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.hardware.Camera;import android.hardware.Camera.Parameters;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class LightActivity extends Activity {Button button = null / / create variables of type Button TextView textView = null; / / create variables of type TextView Camera camera = null; / / create variables of type Camera Parameters params = null; / / create variables of type Parameters Boolean flag = true / / create a variable of type Boolean, which is used to determine whether @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_light); button = (Button) findViewById (R.id.button) / / get Button object textView = (TextView) findViewById (R.id.textView) / / get TextView object button.setOnClickListener (new OnClickListener () {/ / Click event @ Override public void onClick (View v) {if (flag) { Camera = Camera.open () / / get camera params = camera.getParameters (); params.setFlashMode (Parameters.FLASH_MODE_TORCH); camera.setParameters (params); camera.startPreview () TextView.setText (R.string.alert_on); button.setText (R.string.button_off); flag = false } else {params.setFlashMode (Parameters.FLASH_MODE_OFF); camera.setParameters (params); camera.stopPreview (); camera.release () TextView.setText (R.string.alert_off); button.setText (R.string.button_on); flag = true });} public void onBackPressed () {/ / super.onBackPressed (); System.out.println ("sdsfs"); new AlertDialog.Builder (this) .setTitle ("are you sure you want to quit?") .setIcon (R.drawable.ic_launcher) .setPositiveButton ("OK", new DialogInterface.OnClickListener () {@ Override public void onClick (DialogInterface arg0, int arg1) {/ / TODO Auto-generated method stub LightActivity.this.finish () System.exit (0) ) .setNegativeButton ("Cancel", new DialogInterface.OnClickListener () {@ Override public void onClick (DialogInterface arg0) Int arg1) {/ / TODO Auto-generated method stub}}) .show () }} BlueOcean flashlight Hello world! Settings flashlight current status: turn on flashlight current state: turn off flashlight turn off flashlight Author:BlueOcean Thank you for reading this article carefully. I hope the article "how to realize the flashlight function of Android" shared by the editor is helpful to everyone. At the same time, I also hope that you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.