Kommunikation Version 1.5 UDP Socket
This commit is contained in:
parent
e007ad1744
commit
a85fb1f5ca
@ -1,5 +1,8 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
@ -9,6 +12,8 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
@ -19,13 +24,15 @@ import java.nio.ByteOrder;
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
TextView tvMessages;
|
||||
TextView tvConnectionInfos;
|
||||
|
||||
WifiCommunication communication;
|
||||
PermissionRequest permission;
|
||||
public static String SERVER_IP = "";
|
||||
public static final int SERVER_PORT = 1234;
|
||||
//private static final int PERMISSION_REQUEST_CODE = 123;
|
||||
float i=0;
|
||||
|
||||
boolean communicationRunning = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -47,6 +54,59 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*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) {
|
||||
|
||||
Toast.makeText(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) {
|
||||
Toast.makeText(getApplicationContext(),"Kein Recht auf Kamera gewährt.", Toast.LENGTH_SHORT).show();
|
||||
|
||||
if (shouldShowRequestPermissionRationale(CAMERA)) {
|
||||
zeigeDialog("Du musst uns Zugriff auf deine Kamera gestatten, damit deine Umgebung Ueberwacht werden kann.");
|
||||
}
|
||||
}
|
||||
if (!rechtMikrofon) {
|
||||
Toast.makeText(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 die Geraeuschueberwachung funktioniert.");
|
||||
}
|
||||
}
|
||||
if (!rechtInternet) {
|
||||
Toast.makeText(getApplicationContext(),"Kein Recht auf Internet.", 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(this)
|
||||
.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();
|
||||
}*/
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.options_menu, menu);
|
||||
return true;
|
||||
@ -77,7 +137,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
communication = new WifiCommunication(MainActivity.this, SERVER_PORT);
|
||||
if (!communicationRunning){
|
||||
communication = new WifiCommunication(MainActivity.this, SERVER_PORT);
|
||||
communicationRunning = true;
|
||||
}
|
||||
permission = new PermissionRequest(MainActivity.this);
|
||||
permission.rechtePruefen();
|
||||
}
|
||||
|
@ -18,11 +18,7 @@ import androidx.core.content.ContextCompat;
|
||||
public class PermissionRequest extends AppCompatActivity{
|
||||
private static final int PERMISSION_REQUEST_CODE = 123;
|
||||
private final MainActivity mainActivity;
|
||||
|
||||
boolean prüfen= false;
|
||||
|
||||
Handler handler = new Handler();
|
||||
|
||||
public PermissionRequest(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
}
|
||||
@ -49,29 +45,25 @@ public class PermissionRequest extends AppCompatActivity{
|
||||
}
|
||||
|
||||
public void rechteAnfordern() {
|
||||
/*handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(mainActivity.getApplicationContext(),"Fordere Rechte an", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});*/
|
||||
mainActivity.requestPermissions(new String[]{CAMERA, RECORD_AUDIO, INTERNET}, PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@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)
|
||||
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();
|
||||
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() {
|
||||
@ -123,5 +115,5 @@ public class PermissionRequest extends AppCompatActivity{
|
||||
.setNegativeButton("Abbruch", null)
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Aktualisieren"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="italic"
|
||||
android:padding="10dp"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user