Compare commits

...
37 Commits
Author SHA1 Message Date
kohlerba68671 a7a3152953 WIP: audio recorder 2023-06-17 09:39:37 +02:00
kohlerba68671 0ad340bb32 WIP: recorder and detection in one class 2023-06-16 11:03:40 +02:00
kohlerba68671 2e2b400274 Video recorder based on Camerax working. But problems with simultanious VideoDetector 2023-06-16 00:42:27 +02:00
kohlerba68671 6b606683db refactor 2023-06-02 10:40:31 +02:00
kohlerba68671 d37766ffaf Added a second Recorder based on CameraX. Not working yet 2023-06-02 10:17:50 +02:00
kohlerba68671 675d4423e4 refactor 2023-05-31 14:28:28 +02:00
kohlerba68671 63db527f64 Working video recorder based on deprecated camera api 2023-05-31 10:31:02 +02:00
kohlerba68671 8c45cbeb56 Added Recorder Class. Currently only Audio Recording working 2023-05-30 13:13:39 +02:00
kohlerba68671 19d1bfe1e3 Refactor 2023-05-29 10:43:51 +02:00
kohlerba68671 e9da712882 Merge remote-tracking branch 'origin/bk_video' into bk_video 2023-05-28 22:30:58 +02:00
kohlerba68671 804c5aba36 Removed old Luminosity detection 2023-05-28 22:30:22 +02:00
kohlerba68671 c5577b125f Changed VideoDetector.java to detect based on changed pixel count instead of average luminosity 2023-05-28 22:30:22 +02:00
kohlerba68671 6100d17bd2 Refactored in Main 2023-05-28 22:30:22 +02:00
kohlerba68671 74a291bdd6 Removed olf Luminosity detection 2023-05-28 22:28:23 +02:00
kohlerba68671 ba6765b1fb Changed VideoDetector.java to detect based on changed pixel count instead of average luminosity 2023-05-28 22:20:56 +02:00
kohlerba68671 9fce3be6a8 Refactored some stuff in Main 2023-05-28 22:19:30 +02:00
kohlerba68671 9892fc35bc Refactor of Detector.java 2023-05-28 22:19:05 +02:00
kohlerba68671 62a528d33b Implemented VideoDetector as a child class of abstract class Detector 2023-05-28 21:16:17 +02:00
kohlerba68671 37617dbd54 Fixed a bug in Detector.java 2023-05-25 10:54:08 +02:00
kohlerba68671 569bd43163 Adjusted some values in xml and video detector for showcase 2023-05-25 10:20:11 +02:00
kohlerba68671 fdb0036ea6 Added comments to abstract class "Detector" 2023-05-25 10:19:21 +02:00
kohlerba68671 f9797f2dca Added Abstract class Detector 2023-05-24 23:51:49 +02:00
kohlerba68671 ba75c58a23 Refactor 2023-05-24 22:16:54 +02:00
kohlerba68671 3d799ae461 Rebuild Demo in Main Activity 2023-05-18 15:05:09 +02:00
kohlerba68671 2501662737 Fixed a bug in the video decoder 2023-05-18 12:02:18 +02:00
kohlerba68671 d04d166e14 Added log function to detection report 2023-05-18 12:01:45 +02:00
kohlerba68671 1576719d10 Added onDetectionListener to VideoDecoder 2023-05-16 22:35:50 +02:00
kohlerba68671 362af75b9a Added DetectionReportCalss 2023-05-16 22:34:32 +02:00
kohlerba68671 bef5d03494 Added functions for checking luminosity violation 2023-05-16 19:15:57 +02:00
kohlerba68671 80ebf77eb6 Removed empty Text File 2023-05-16 17:48:33 +02:00
kohlerba68671 c4ed247a05 added Functions to VideoDetector:
startDetection(), stopDetection(), isRunning()
2023-05-16 17:42:10 +02:00
kohlerba68671 323786859e added Video Decoder Class 2023-05-12 18:45:13 +02:00
kohlerba68671 354bf937b2 added camerax libraries to build.gradle 2023-05-12 09:37:58 +02:00
kohlerba68671 39bb37f5c3 removed VideoDetection.java 2023-05-11 21:46:15 +02:00
kohlerba68671 b198dc2e06 small refactor 2023-05-11 21:33:40 +02:00
BepsiKohler d83cd3dc32 Added camera access permission 2023-05-11 20:58:01 +02:00
kohlerba68671 065acefeb9 Merge branch 'ms' of siebenhaarmi76624/MDT5_1_Ueberwachungssystem_G1 into master 2023-05-11 13:29:40 +00:00
10 changed files with 707 additions and 3 deletions
View File
+9
View File
@@ -36,4 +36,13 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
// Required for CameraX
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}"
implementation "androidx.camera:camera-video:${camerax_version}"
implementation "androidx.camera:camera-view:${camerax_version}"
implementation "androidx.camera:camera-extensions:${camerax_version}"
}
+5
View File
@@ -2,6 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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.RECORD_AUDIO" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
@@ -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();
}
}
}
@@ -0,0 +1,36 @@
package com.example.ueberwachungssystem.Detection;
import android.util.Log;
import java.util.Calendar;
/** Detection Report Class */
public class DetectionReport {
public String timeStamp;
public String detectionType;
public float detectedValue;
public String detectorID;
public DetectionReport(String detectorID, String detectionType, float detectedAmplitude) {
this.timeStamp = String.valueOf(Calendar.getInstance().getTime());
this.detectionType = detectionType;
this.detectedValue = detectedAmplitude;
this.detectorID = detectorID;
}
/** Get Detection Report in String format */
public String toString() {
String time = "Time: " + "[" + this.timeStamp + "]";
String type = "Type: " + "[" + this.detectionType + "]";
String value = "Value: " + "[" + this.detectedValue + "]";
String id = "ID: " + "[" + this.detectorID + "]";
return String.join("\t", time, type, value, id);
}
/** Debug Report */
public void log(String tag) {
Log.d(tag, this.toString());
}
}
@@ -0,0 +1,38 @@
package com.example.ueberwachungssystem.Detection;
import androidx.annotation.NonNull;
abstract public class Detector {
private OnDetectionListener listener;
/** Constructor - takes context of current activity */
public Detector() {}
/** On Detection Listener - runs when violation is reported */
public interface OnDetectionListener {
void onDetection(@NonNull DetectionReport detectionReport);
}
public void setOnDetectionListener(@NonNull OnDetectionListener listener) {
this.listener = listener;
}
/** Triggers onDetectionListener - call this to trigger violation/alarm */
public void reportViolation(String detectorID, String detectionType, float amplitude) {
if (listener != null) {
DetectionReport detectionReport = new DetectionReport(detectorID, detectionType, amplitude);
listener.onDetection(detectionReport);
} else {
throw new IllegalStateException("No listener set for violation reporting");
}
}
/** Starts Detection (abstract method: needs to be overridden in child class) */
public abstract void startDetection();
/** Stops Detection (abstract method: needs to be overridden in child class) */
public abstract void stopDetection();
}
@@ -0,0 +1,257 @@
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.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 {
// Calling Activity
private final Context context;
// Camera Provider
private ProcessCameraProvider cameraProvider;
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 = 0.2f; // Percent of pixels changed
private ByteBuffer previousBuffer = null;
/**
* Constructor
* @param context: the context of calling activity (usually "this")
* */
public VideoDetector(Context context) {
super();
this.context = context;
}
/**
* Starts the Video Detection
* */
@Override
public void startDetection() {
if (isDetectionRunning)
return;
// Request Camera Provider
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(context);
//Check for Camera availability
cameraProviderFuture.addListener(() -> {
try {
cameraProvider = cameraProviderFuture.get();
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));
}
/**
* Stops the Video Detection
* */
@Override
public void stopDetection() {
if (!isDetectionRunning)
return;
cameraProvider.unbindAll();
isDetectionRunning = false;
}
/**
* 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)
* @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));
builder.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST);
builder.setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888);
ImageAnalysis imageAnalysis = builder.build();
// Set Analyzer
imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(context), imageProxy -> {
if (imageProxy.getFormat() == ImageFormat.YUV_420_888) {
Image image = imageProxy.getImage();
assert image != null;
// Changed Pixel Detection
int pixelChanged = getChangedPixelCount(image);
int width = image.getWidth();
int height = image.getHeight();
float percentPixelChanged = (float) 100f * pixelChanged / (width * height);
if (percentPixelChanged > ALARM_THRESHOLD)
reportViolation("0", "Video", percentPixelChanged);
}
imageProxy.close();
});
// Create Preview
Preview preview = new Preview.Builder().build();
// Specify which Camera to use
CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build();
// Update PreviewView if set
if (previewView != null)
preview.setSurfaceProvider(previewView.getSurfaceProvider());
videoCapture = new VideoCapture.Builder()
.setVideoFrameRate(30)
.setTargetRotation(Surface.ROTATION_0)
.build();
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, imageAnalysis, videoCapture);
}
@SuppressLint("RestrictedApi")
public void startRecording() {
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();
if (previousBuffer == null) {
previousBuffer = ByteBuffer.allocate(buffer.capacity());
buffer.rewind();
previousBuffer.put(buffer);
previousBuffer.rewind();
return 0;
}
int width = image.getWidth();
int height = image.getHeight();
int yRowStride = image.getPlanes()[0].getRowStride();
int yPixelStride = image.getPlanes()[0].getPixelStride();
int changedPixelCount = 0;
// Count changed pixels
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; x++) {
int index = (y * yRowStride) + (x * yPixelStride);
int luminosity = (buffer.get(index) & 0xff);
int previousLuminosity = (previousBuffer.get(index) & 0xff);
int diff = Math.abs(luminosity - previousLuminosity);
if (diff > PIXEL_THRESHOLD)
changedPixelCount++;
}
}
// Reset and copy Byte Buffer
buffer.rewind();
previousBuffer.rewind();
previousBuffer.put(buffer);
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();
}
}
@@ -1,14 +1,120 @@
package com.example.ueberwachungssystem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.view.PreviewView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
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.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 PERMISSION_REQUEST_CODE = 111;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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();
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) {
getRecordVideoAccess();
File[] files = directory.listFiles();
textView.setText(Arrays.toString(files));
if (isRecordVideoAllowed() && toggleButton.isChecked())
{
ar.startRecording();
//vd.startRecording();
//vd.playVideo(videoView);
//detectionRecorder.playVideo(videoView);
//detectionRecorder.start();
}
else {
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 isRecordVideoAllowed() {
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
}
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 == PERMISSION_REQUEST_CODE && grantResults.length > 0) {
boolean cameraRights = grantResults[0] == PackageManager.PERMISSION_GRANTED;
boolean recordAudioRights = grantResults[1] == PackageManager.PERMISSION_GRANTED;
if (cameraRights && recordAudioRights) {
Toast.makeText(this, "permissions granted", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "permissions denied", Toast.LENGTH_LONG).show();
}
}
}
}
+33 -3
View File
@@ -1,18 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text=""
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ToggleButton
android:id="@+id/previewButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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="200dp" />
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>