setup the camera
This commit is contained in:
parent
6b61e09198
commit
9e679fafba
|
@ -1,6 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="flashlight.simplemobiletools.com"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest
|
||||
package="flashlight.simplemobiletools.com"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-feature
|
||||
android:name="android.hardware.camera"
|
||||
android:required="false"/>
|
||||
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT"/>
|
||||
<uses-feature
|
||||
android:name="android.hardware.camera.flash"
|
||||
android:required="true"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -16,5 +27,4 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -1,13 +1,57 @@
|
|||
package flashlight.simplemobiletools.com;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private Camera camera;
|
||||
private Camera.Parameters params;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
setupCamera();
|
||||
}
|
||||
|
||||
private void setupCamera() {
|
||||
if (camera == null) {
|
||||
camera = Camera.open();
|
||||
params = camera.getParameters();
|
||||
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
||||
camera.setParameters(params);
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseCamera() {
|
||||
if (camera != null) {
|
||||
camera.release();
|
||||
camera = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
setupCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
setupCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
releaseCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
releaseCamera();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,4 @@
|
|||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="flashlight.simplemobiletools.com.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"/>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in New Issue