Compare commits
8 Commits
master
...
bk_recordi
Author | SHA1 | Date | |
---|---|---|---|
a7a3152953 | |||
0ad340bb32 | |||
2e2b400274 | |||
6b606683db | |||
d37766ffaf | |||
675d4423e4 | |||
63db527f64 | |||
8c45cbeb56 |
@ -38,7 +38,7 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
|
||||
// Required for CameraX
|
||||
def camerax_version = "1.2.2"
|
||||
def camerax_version = "1.2.3"
|
||||
implementation "androidx.camera:camera-core:${camerax_version}"
|
||||
implementation "androidx.camera:camera-camera2:${camerax_version}"
|
||||
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
||||
|
@ -3,7 +3,9 @@
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-feature android:name="android.hardware.camera"/>
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -0,0 +1,76 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Camera;
|
||||
import android.media.CamcorderProfile;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.MediaRecorder;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceView;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AudioRecorder {
|
||||
private final Context context;
|
||||
private Camera camera;
|
||||
private MediaRecorder mediaRecorder = null;
|
||||
private SurfaceView surfaceView;
|
||||
|
||||
public AudioRecorder (Context context) {
|
||||
this.context = context;
|
||||
this.surfaceView = new SurfaceView(context);
|
||||
}
|
||||
|
||||
|
||||
public void startRecording() {
|
||||
|
||||
mediaRecorder = new MediaRecorder();
|
||||
|
||||
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
||||
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
|
||||
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
|
||||
mediaRecorder.setOutputFile(context.getFilesDir() + "/audio.mp3");
|
||||
|
||||
|
||||
try {
|
||||
mediaRecorder.prepare();
|
||||
mediaRecorder.start();
|
||||
} catch (IOException e) {
|
||||
Log.e("audioRecorder", "prepare() failed");
|
||||
}
|
||||
}
|
||||
|
||||
public void stopRecording() {
|
||||
if (mediaRecorder != null) {
|
||||
try {
|
||||
mediaRecorder.stop();
|
||||
mediaRecorder.release();
|
||||
mediaRecorder = null;
|
||||
} catch (RuntimeException e) {
|
||||
// RuntimeException may be thrown if the MediaRecorder is in an invalid state
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playAudio() {
|
||||
MediaPlayer mp = new MediaPlayer();
|
||||
try {
|
||||
mp.setDataSource(context.getFilesDir() + "/audio.mp3");
|
||||
mp.prepare();
|
||||
mp.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteRecording(){
|
||||
File file = new File(context.getFilesDir() + "/audio.mp3");
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
package com.example.ueberwachungssystem.Detection;
|
||||
|
||||
import android.util.Log;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
package com.example.ueberwachungssystem.Detection;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -1,26 +1,51 @@
|
||||
package com.example.ueberwachungssystem.VideoDetection;
|
||||
package com.example.ueberwachungssystem.Detection;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.ImageFormat;
|
||||
import android.media.Image;
|
||||
import android.util.Size;
|
||||
import android.view.Surface;
|
||||
import android.widget.Toast;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.camera.core.CameraSelector;
|
||||
import androidx.camera.core.ExperimentalGetImage;
|
||||
import androidx.camera.core.ImageAnalysis;
|
||||
import androidx.camera.core.Preview;
|
||||
import androidx.camera.core.VideoCapture;
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||
import androidx.camera.view.PreviewView;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.example.ueberwachungssystem.Detector;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
||||
/**
|
||||
* Video Detector inherits some methods from abstract Detector class (more info there)
|
||||
*
|
||||
*
|
||||
* USE FROM MAIN ACTIVITY:
|
||||
*
|
||||
* VideoDetector vd = new VideoDetector(this);
|
||||
* vd.setPreview(previewView); //THIS IS OPTIONAL!
|
||||
* vd.setOnDetectionListener(new Detector.OnDetectionListener{...});
|
||||
* vd.startDetection();
|
||||
* vd.stopDetection
|
||||
*
|
||||
* */
|
||||
|
||||
|
||||
@ExperimentalGetImage
|
||||
public class VideoDetector extends Detector {
|
||||
|
||||
@ -31,21 +56,26 @@ public class VideoDetector extends Detector {
|
||||
private Boolean isDetectionRunning = false;
|
||||
// Preview Camera Image
|
||||
private PreviewView previewView = null;
|
||||
private VideoCapture videoCapture = null;
|
||||
// Detect Violation
|
||||
private static final float PIXEL_THRESHOLD = 30f; // Luminosity (brightness channel of YUV_420_888)
|
||||
private static final float ALARM_THRESHOLD = 1f; // Percent of pixels changed
|
||||
private static final float ALARM_THRESHOLD = 0.2f; // Percent of pixels changed
|
||||
private ByteBuffer previousBuffer = null;
|
||||
|
||||
|
||||
|
||||
/** Constructor */
|
||||
/**
|
||||
* Constructor
|
||||
* @param context: the context of calling activity (usually "this")
|
||||
* */
|
||||
public VideoDetector(Context context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
/** Starts Video Detection */
|
||||
/**
|
||||
* Starts the Video Detection
|
||||
* */
|
||||
@Override
|
||||
public void startDetection() {
|
||||
if (isDetectionRunning)
|
||||
@ -56,17 +86,19 @@ public class VideoDetector extends Detector {
|
||||
cameraProviderFuture.addListener(() -> {
|
||||
try {
|
||||
cameraProvider = cameraProviderFuture.get();
|
||||
bindLuminosityAnalysis(cameraProvider);
|
||||
bindAnalysis(cameraProvider);
|
||||
isDetectionRunning = true;
|
||||
previousBuffer = null;
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
// No errors need to be handled for this Future. This should never be reached.
|
||||
}
|
||||
},ContextCompat.getMainExecutor(context));
|
||||
}, ContextCompat.getMainExecutor(context));
|
||||
}
|
||||
|
||||
|
||||
/** Stops Video Detection */
|
||||
/**
|
||||
* Stops the Video Detection
|
||||
* */
|
||||
@Override
|
||||
public void stopDetection() {
|
||||
if (!isDetectionRunning)
|
||||
@ -76,14 +108,21 @@ public class VideoDetector extends Detector {
|
||||
}
|
||||
|
||||
|
||||
/** Set PreviewView to show Image */
|
||||
/**
|
||||
* Set PreviewView to show video feed while detecting
|
||||
* this is optional and does not need to be called
|
||||
* */
|
||||
public void setPreviewView(PreviewView previewView) {
|
||||
this.previewView = previewView;
|
||||
}
|
||||
|
||||
|
||||
/** Binds the Luminosity Analyzer (configure and run Analysis) */
|
||||
private void bindLuminosityAnalysis(@NonNull ProcessCameraProvider cameraProvider) {
|
||||
/**
|
||||
* Binds the Luminosity Analyzer (configure and run Analysis)
|
||||
* @param cameraProvider: CameraProvider of Context passed by Constructor
|
||||
* */
|
||||
@SuppressLint("RestrictedApi")
|
||||
private void bindAnalysis(@NonNull ProcessCameraProvider cameraProvider) {
|
||||
// Configure and create Image Analysis
|
||||
ImageAnalysis.Builder builder = new ImageAnalysis.Builder();
|
||||
builder.setTargetResolution(new Size(640, 480));
|
||||
@ -117,12 +156,60 @@ public class VideoDetector extends Detector {
|
||||
if (previewView != null)
|
||||
preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
||||
|
||||
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, imageAnalysis, preview);
|
||||
videoCapture = new VideoCapture.Builder()
|
||||
.setVideoFrameRate(30)
|
||||
.setTargetRotation(Surface.ROTATION_0)
|
||||
.build();
|
||||
|
||||
|
||||
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, imageAnalysis, videoCapture);
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
public void startRecording() {
|
||||
|
||||
/** Calculate Amount of Pixels changed */
|
||||
File dir = context.getFilesDir();
|
||||
String filename = "recording";
|
||||
String vidFilePath = dir.getAbsolutePath() + "/" + filename + ".mp4";
|
||||
File vidFile = new File(vidFilePath);
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
||||
// TODO: Consider calling
|
||||
// ActivityCompat#requestPermissions
|
||||
// here to request the missing permissions, and then overriding
|
||||
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
||||
// int[] grantResults)
|
||||
// to handle the case where the user grants the permission. See the documentation
|
||||
// for ActivityCompat#requestPermissions for more details.
|
||||
return;
|
||||
}
|
||||
videoCapture.startRecording(
|
||||
new VideoCapture.OutputFileOptions.Builder(vidFile).build(),
|
||||
context.getMainExecutor(),
|
||||
new VideoCapture.OnVideoSavedCallback() {
|
||||
@Override
|
||||
public void onVideoSaved(@NonNull VideoCapture.OutputFileResults outputFileResults) {
|
||||
Toast.makeText(context, "recording saved", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
|
||||
Toast.makeText(context, "recording failed", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
public void stopRecording(){
|
||||
videoCapture.stopRecording();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Amount of Pixels changed using a threshold
|
||||
* @param image
|
||||
* */
|
||||
private int getChangedPixelCount(Image image) {
|
||||
Image.Plane[] planes = image.getPlanes();
|
||||
ByteBuffer buffer = planes[0].getBuffer();
|
||||
@ -162,4 +249,9 @@ public class VideoDetector extends Detector {
|
||||
|
||||
return changedPixelCount;
|
||||
}
|
||||
|
||||
public void playVideo(VideoView videoView) {
|
||||
videoView.setVideoPath(context.getFilesDir() + "/recording.mp4");
|
||||
videoView.start();
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.view.Surface;
|
||||
import android.widget.Toast;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.camera.core.CameraSelector;
|
||||
import androidx.camera.core.Preview;
|
||||
import androidx.camera.core.VideoCapture;
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||
import androidx.camera.view.PreviewView;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class DetectionRecorder {
|
||||
|
||||
private final Context context;
|
||||
private ProcessCameraProvider cameraProvider;
|
||||
private VideoCapture videoCapture = null;
|
||||
private PreviewView previewView = null;
|
||||
private boolean isRunning = false;
|
||||
private boolean isVideoPlaying = false;
|
||||
|
||||
|
||||
// Constructor
|
||||
public DetectionRecorder(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void start() {
|
||||
if (isRunning)
|
||||
return;
|
||||
isRunning = true;
|
||||
|
||||
// Request Camera Provider
|
||||
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(context);
|
||||
//Check for Camera availability
|
||||
cameraProviderFuture.addListener(() -> {
|
||||
try {
|
||||
cameraProvider = cameraProviderFuture.get();
|
||||
startCameraX(cameraProvider);
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
// No errors need to be handled for this Future. This should never be reached.
|
||||
}
|
||||
}, ContextCompat.getMainExecutor(context));
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
public void stop() {
|
||||
if (!isRunning)
|
||||
return;
|
||||
|
||||
videoCapture.stopRecording();
|
||||
cameraProvider.unbind(videoCapture);
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
private void startCameraX(ProcessCameraProvider cameraProvider) {
|
||||
//cameraProvider.unbindAll();
|
||||
|
||||
CameraSelector cameraSelector = new CameraSelector.Builder()
|
||||
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
|
||||
.build();
|
||||
|
||||
// Preview Use Case
|
||||
Preview preview = new Preview.Builder().build();
|
||||
if (previewView != null)
|
||||
preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
||||
|
||||
// Video Capture Use Case
|
||||
videoCapture = new VideoCapture.Builder()
|
||||
.setVideoFrameRate(30)
|
||||
.setTargetRotation(Surface.ROTATION_0)
|
||||
.build();
|
||||
|
||||
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, preview, videoCapture);
|
||||
|
||||
|
||||
File dir = context.getFilesDir();
|
||||
String filename = "recording";
|
||||
String vidFilePath = dir.getAbsolutePath() + "/" + filename + ".mp4";
|
||||
File vidFile = new File(vidFilePath);
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
||||
// TODO: Consider calling
|
||||
// ActivityCompat#requestPermissions
|
||||
// here to request the missing permissions, and then overriding
|
||||
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
||||
// int[] grantResults)
|
||||
// to handle the case where the user grants the permission. See the documentation
|
||||
// for ActivityCompat#requestPermissions for more details.
|
||||
return;
|
||||
}
|
||||
videoCapture.startRecording(
|
||||
new VideoCapture.OutputFileOptions.Builder(vidFile).build(),
|
||||
context.getMainExecutor(),
|
||||
new VideoCapture.OnVideoSavedCallback() {
|
||||
@Override
|
||||
public void onVideoSaved(@NonNull VideoCapture.OutputFileResults outputFileResults) {
|
||||
Toast.makeText(context, "recording saved", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@Override
|
||||
public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
|
||||
Toast.makeText(context, "recording failed", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/** Set PreviewView to show Image */
|
||||
public void setPreviewView(PreviewView previewView) {
|
||||
this.previewView = previewView;
|
||||
}
|
||||
|
||||
private void playAudio() {
|
||||
MediaPlayer mp = new MediaPlayer();
|
||||
try {
|
||||
mp.setDataSource(context.getFilesDir() + "/audio.gpp");
|
||||
mp.prepare();
|
||||
mp.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void playVideo(VideoView videoView) {
|
||||
if (isVideoPlaying)
|
||||
return;
|
||||
videoView.setVideoPath(context.getFilesDir() + "/recording.mp4");
|
||||
videoView.start();
|
||||
}
|
||||
}
|
@ -10,17 +10,24 @@ import androidx.camera.core.ExperimentalGetImage;
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import com.example.ueberwachungssystem.VideoDetection.VideoDetector;
|
||||
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
||||
import com.example.ueberwachungssystem.Detection.Detector;
|
||||
import com.example.ueberwachungssystem.Detection.VideoDetector;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ExperimentalGetImage
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private static final int CAMERA_PERMISSION_REQUEST_CODE = 101;
|
||||
private static final int PERMISSION_REQUEST_CODE = 111;
|
||||
|
||||
|
||||
@Override
|
||||
@ -29,57 +36,84 @@ public class MainActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
TextView textView = findViewById(R.id.textView);
|
||||
VideoView videoView = findViewById(R.id.videoView);
|
||||
PreviewView previewView = findViewById(R.id.previewView);
|
||||
|
||||
File directory = getFilesDir();
|
||||
|
||||
VideoDetector vd = new VideoDetector(this);
|
||||
vd.setPreviewView(previewView);
|
||||
vd.setOnDetectionListener(new VideoDetector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
detectionReport.log("OnDetection");
|
||||
textView.setText(detectionReport.toString());
|
||||
}
|
||||
});
|
||||
//vd.startDetection();
|
||||
|
||||
AudioRecorder ar = new AudioRecorder(this);
|
||||
|
||||
|
||||
//DetectionRecorder detectionRecorder = new DetectionRecorder(this);
|
||||
//detectionRecorder.setPreviewView(previewView);
|
||||
|
||||
ToggleButton toggleButton = findViewById(R.id.previewButton);
|
||||
ToggleButton toggleButton2 = findViewById(R.id.toggleButton2);
|
||||
|
||||
toggleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getCameraAccess();
|
||||
if (isCameraAccessAllowed() && toggleButton.isChecked())
|
||||
getRecordVideoAccess();
|
||||
File[] files = directory.listFiles();
|
||||
textView.setText(Arrays.toString(files));
|
||||
|
||||
if (isRecordVideoAllowed() && toggleButton.isChecked())
|
||||
{
|
||||
vd.startDetection();
|
||||
ar.startRecording();
|
||||
//vd.startRecording();
|
||||
//vd.playVideo(videoView);
|
||||
//detectionRecorder.playVideo(videoView);
|
||||
//detectionRecorder.start();
|
||||
}
|
||||
else {
|
||||
vd.stopDetection();
|
||||
textView.setText("");
|
||||
ar.stopRecording();
|
||||
//vd.stopRecording();
|
||||
|
||||
//detectionRecorder.stop();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
toggleButton2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (toggleButton.isChecked())
|
||||
{
|
||||
ar.playAudio();
|
||||
}
|
||||
else {
|
||||
ar.deleteRecording();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isCameraAccessAllowed() {
|
||||
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
|
||||
private boolean isRecordVideoAllowed() {
|
||||
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED &&
|
||||
ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
private void getCameraAccess() {
|
||||
if (!isCameraAccessAllowed())
|
||||
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE);
|
||||
private void getRecordVideoAccess() {
|
||||
if (!isRecordVideoAllowed()) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}, PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE && grantResults.length > 0) {
|
||||
if (requestCode == PERMISSION_REQUEST_CODE && grantResults.length > 0) {
|
||||
|
||||
boolean cameraRights = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||
if (cameraRights) {
|
||||
Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show();
|
||||
boolean recordAudioRights = grantResults[1] == PackageManager.PERMISSION_GRANTED;
|
||||
|
||||
if (cameraRights && recordAudioRights) {
|
||||
Toast.makeText(this, "permissions granted", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(this, "permissions denied", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,21 @@
|
||||
android:text="ToggleButton" />
|
||||
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/toggleButton2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="ToggleButton" />
|
||||
|
||||
<androidx.camera.view.PreviewView
|
||||
android:id="@+id/previewView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:backgroundTint="@android:color/black"/>
|
||||
android:layout_height="200dp" />
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/videoView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
||||
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user