日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

手电筒android studio,Android Studio:手电筒关闭时崩溃

發布時間:2025/3/12 Android 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 手电筒android studio,Android Studio:手电筒关闭时崩溃 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試圖開發手電筒應用程序作為我的第一個“真正”的應用程序,幾乎所有的工作。但每次我想關閉手電筒時,我的應用程序都會崩潰。代碼和logcat的日志如下:Android Studio:手電筒關閉時崩潰

package com.leuchtstein.flashlight;

import android.hardware.Camera;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

public boolean stat = false;

TextView text;

Camera camera;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

text = (TextView) findViewById(R.id.textView);

}

public void triggerlight(View view) {

if (stat == false) {

camera = Camera.open();

Camera.Parameters parameters = camera.getParameters();

parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);

camera.setParameters(parameters);

camera.startPreview();

text.setText("ON");

stat = true;

} else {

camera = Camera.open();

Camera.Parameters parameters = camera.getParameters();

parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);

camera.setParameters(parameters);

camera.stopPreview();

camera.release();

text.setText("OFF");

stat = false;

}

}

}

activity_main.xml中

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.leuchtstein.flashlight.MainActivity">

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="16dp"

android:text="@string/desc_textview"

android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"

app:layout_constraintHorizontal_bias="0.95"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent" />

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:onClick="triggerlight"

android:text="Turn on/off"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView"

app:layout_constraintVertical_bias="0.387" />

logcat的:提前

https://pastebin.com/tNyF6GvX

謝謝,leuchtstein。

編輯:是的,我有用途的許可功能:

package="com.leuchtstein.flashlight">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

總結

以上是生活随笔為你收集整理的手电筒android studio,Android Studio:手电筒关闭时崩溃的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。