|
|
|
|
|
|
|
|
public class PermissionRequest extends AppCompatActivity{ |
|
|
public class PermissionRequest extends AppCompatActivity{ |
|
|
private static final int PERMISSION_REQUEST_CODE = 123; |
|
|
private static final int PERMISSION_REQUEST_CODE = 123; |
|
|
private final MainActivity mainActivity; |
|
|
private final MainActivity mainActivity; |
|
|
|
|
|
|
|
|
|
|
|
boolean prüfen= false; |
|
|
|
|
|
|
|
|
Handler handler = new Handler(); |
|
|
Handler handler = new Handler(); |
|
|
|
|
|
|
|
|
public PermissionRequest(MainActivity mainActivity) { |
|
|
public PermissionRequest(MainActivity mainActivity) { |
|
|
this.mainActivity = mainActivity; |
|
|
this.mainActivity = mainActivity; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void rechteAnfordern() { |
|
|
public void rechteAnfordern() { |
|
|
mainActivity.requestPermissions(new String[]{CAMERA, RECORD_AUDIO, INTERNET}, PERMISSION_REQUEST_CODE); |
|
|
mainActivity.requestPermissions(new String[]{CAMERA, RECORD_AUDIO, INTERNET}, PERMISSION_REQUEST_CODE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*@Override |
|
|
|
|
|
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { |
|
|
|
|
|
if (requestCode == PERMISSION_REQUEST_CODE && grantResults.length > 0) { |
|
|
|
|
|
boolean rechtKamera = grantResults[0] == PackageManager.PERMISSION_GRANTED; |
|
|
|
|
|
boolean rechtMikrofon = grantResults[1] == PackageManager.PERMISSION_GRANTED; |
|
|
|
|
|
boolean rechtInternet = grantResults[2] == PackageManager.PERMISSION_GRANTED; |
|
|
|
|
|
|
|
|
|
|
|
if (rechtKamera && rechtMikrofon && rechtInternet) { |
|
|
|
|
|
handler.post(new Runnable() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void run() { |
|
|
|
|
|
Toast.makeText(mainActivity.getApplicationContext(), "Alle benötigten Rechte sind gewährt.", Toast.LENGTH_LONG).show(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText("Alle benötigten Rechte sind gewährt")); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if (!rechtKamera) { |
|
|
|
|
|
handler.post(new Runnable() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void run() { |
|
|
|
|
|
Toast.makeText(mainActivity.getApplicationContext(),"Kein Recht auf Kamera gewährt.", Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
if (shouldShowRequestPermissionRationale(CAMERA)) { |
|
|
|
|
|
zeigeDialog("Du musst uns Zugriff auf deine Kamera gestatten, damit wir dich besser sehen können."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (!rechtMikrofon) { |
|
|
|
|
|
handler.post(new Runnable() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void run() { |
|
|
|
|
|
Toast.makeText(mainActivity.getApplicationContext(),"Kein Recht auf Mikrofon gewährt.", Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
if (shouldShowRequestPermissionRationale(RECORD_AUDIO)) { |
|
|
|
|
|
zeigeDialog("Du musst uns Zugriff auf dein Mikrofon gestatten, damit wir dich besser hören können."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (!rechtInternet) { |
|
|
|
|
|
handler.post(new Runnable() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void run() { |
|
|
|
|
|
Toast.makeText(mainActivity.getApplicationContext(),"Kein Recht auf Ortung gewährt.", Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
if (shouldShowRequestPermissionRationale(INTERNET)) { |
|
|
|
|
|
zeigeDialog("Du musst uns Zugriff auf dein Internet gestatten, damit wir eine Verbindung aufbauen können."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void zeigeDialog(String begruendung) { |
|
|
|
|
|
new AlertDialog.Builder(mainActivity.getApplicationContext()) |
|
|
|
|
|
.setMessage(begruendung) |
|
|
|
|
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
|
|
requestPermissions(new String[]{CAMERA, RECORD_AUDIO, INTERNET}, PERMISSION_REQUEST_CODE); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.setNegativeButton("Abbruch", null) |
|
|
|
|
|
.create() |
|
|
|
|
|
.show(); |
|
|
|
|
|
}*/ |
|
|
|
|
|
} |
|
|
} |