Android 手电筒不发光';当我按“后退”按钮时,你不能关机
我已经创建了一个手电筒应用程序…一切都很好…除了当手电筒打开,我按下后退按钮…它保持打开…并且没有停止…怎么办?。我使用了onpause方法,但它似乎不工作 另外,如果有人能向我解释参数的使用,我将非常感激。我已经从网上获得了这个项目的帮助。我不懂参数法……有人能详细解释一下吗? 提前感谢……) 我的XML:Android 手电筒不发光';当我按“后退”按钮时,你不能关机,android,onpause,Android,Onpause,我已经创建了一个手电筒应用程序…一切都很好…除了当手电筒打开,我按下后退按钮…它保持打开…并且没有停止…怎么办?。我使用了onpause方法,但它似乎不工作 另外,如果有人能向我解释参数的使用,我将非常感激。我已经从网上获得了这个项目的帮助。我不懂参数法……有人能详细解释一下吗? 提前感谢……) 我的XML: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/aaaaaaa"
tools:context=".Flash" >
<ImageButton
android:id="@+id/ib2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" /></RelativeLayout>
舱单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.potapptoes.flashlight"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.potapptoes.flashlight.Flash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
你可以试试这个
para.setFlashMode(Parameters.FLASH_MODE_OFF);
cam.setParameters(para);
cam.release();
cam = null;
在您的
onpause
或可能在onBackPressed
中,查看它是否有效 只需使用您的工作代码在onPause()中关闭手电筒即可。我很高兴它能工作:),但不要忘记在它周围设置一个条件,以检查手电筒是否处于打开或关闭状态。:)
para.setFlashMode(Parameters.FLASH_MODE_OFF);
cam.setParameters(para);
cam.release();
cam = null;