|
|
|
|
|
|
|
|
package com.example.ueberwachungssystem; |
|
|
package com.example.ueberwachungssystem; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
import androidx.core.app.ActivityCompat; |
|
|
|
|
|
import androidx.core.content.ContextCompat; |
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest; |
|
|
|
|
|
import android.app.AlertDialog; |
|
|
|
|
|
import android.content.DialogInterface; |
|
|
|
|
|
import android.content.pm.PackageManager; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
|
|
|
import android.view.View; |
|
|
|
|
|
import android.widget.Button; |
|
|
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity { |
|
|
public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
|
|
|
|
private static final int CAMERA_PERMISSION_REQUEST_CODE = 101; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
super.onCreate(savedInstanceState); |
|
|
super.onCreate(savedInstanceState); |
|
|
setContentView(R.layout.activity_main); |
|
|
setContentView(R.layout.activity_main); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Button B1 = findViewById(R.id.B1); |
|
|
|
|
|
B1.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
getCameraAccess(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isCameraAccessAllowed() { |
|
|
|
|
|
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void getCameraAccess() { |
|
|
|
|
|
if (!isCameraAccessAllowed()) |
|
|
|
|
|
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CAMERA}, CAMERA_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) { |
|
|
|
|
|
boolean cameraRights = grantResults[0] == PackageManager.PERMISSION_GRANTED; |
|
|
|
|
|
if (cameraRights) { |
|
|
|
|
|
Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show(); |
|
|
|
|
|
} else { |
|
|
|
|
|
Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void showDialogue(String message) { |
|
|
|
|
|
new AlertDialog.Builder(this) |
|
|
|
|
|
.setMessage(message) |
|
|
|
|
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
|
|
requestPermissions(new String[] {Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.setNegativeButton("Cancel", null) |
|
|
|
|
|
.create() |
|
|
|
|
|
.show(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |