SoFunction
Updated on 2025-03-01

Android studio writes a simple flashlight app

A very good flashlight APP, I will share it with you, I hope you like it.

1. Java code

package ;
 
import ;
import ;
import ;
import ;
import ;
import ;
 
 
public class FireActivity extends Activity {
  private Button button;
  private Camera camera = ();
  private Parameters parameters;
  private boolean islight=true;
 
  public void onCreate(Bundle savedInstanceState) {
   (savedInstanceState);
   setContentView(.activity_fire);
   button = (Button) ();
   (new () {
     @Override
     public void onClick(View v) {
      if (islight) {
        ();
        parameters = ();
        (Parameters.FLASH_MODE_TORCH);
        (parameters);
        islight = false
        ;
        ("close");
      } else {
        parameters = ();
        (Parameters.FLASH_MODE_OFF);
        (parameters);
        islight = true;
        ("open");
      }
     }
 
   });
  }
}

2.

package ;
 
import ;
import ;
import ;
import ;
import ;
import ;
 
 
public class FireActivity extends Activity {
  private Button button;
  private Camera camera = ();
  private Parameters parameters;
  private boolean islight=true;
 
  public void onCreate(Bundle savedInstanceState) {
   (savedInstanceState);
   setContentView(.activity_fire);
   button = (Button) ();
   (new () {
     @Override
     public void onClick(View v) {
      if (islight) {
        ();
        parameters = ();
        (Parameters.FLASH_MODE_TORCH);
        (parameters);
        islight = false
        ;
        ("close");
      } else {
        parameters = ();
        (Parameters.FLASH_MODE_OFF);
        (parameters);
        islight = true;
        ("open");
      }
     }
 
   });
  }
}

3. content_fire.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:andro
  xmlns:app="/apk/res-auto"
  xmlns:tools="/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  app:layout_behavior="@string/appbar_scrolling_view_behavior"
  tools:context=""
  tools:showIn="@layout/activity_fire">
 
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Flash Mode"
    android:textSize="34sp"
    android:textStyle="bold"
    android:gravity="center"/>
  <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:
    android:textOff="close"
    android:textOn="open"
    android:height="400dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="59dp"
    android:fontFeatureSettings="@string/auth_google_play_services_client_facebook_display_name"
    android:textColor="@color/common_signin_btn_dark_text_focused"
    android:textStyle="bold"
    android:textSize="100sp"
    />
 
 
</RelativeLayout>

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.