kundennummer = kundennummer_edit.getText().toString().trim();
betrag = betrag_edit.getText().toString().trim();
verwendungszweck = verwendungszweck_edit.getText().toString().trim();
if (kundennummer.isEmpty() | betrag.isEmpty()){
if (kundennummer.isEmpty()){
kundennummer_edit.setError("Kundennummer ist leer!");
kundennummer_edit.requestFocus();
}else if (betrag.isEmpty()){
betrag_edit.setError("Betrag ist leer!");
betrag_edit.requestFocus();
}else if (kundennummer.isEmpty() && betrag.isEmpty()){
kundennummer_edit.setError("Kundennummer ist leer!");
kundennummer_edit.requestFocus();
betrag_edit.setError("Betrag ist leer!");
betrag_edit.requestFocus();
}
}else {
if (verwendungszweck.isEmpty()){
verwengungsanzahl = "kein Verwendungszweck";
}else{
verwengungsanzahl = "Verwendungszweck";
}
aLoadingDialog.show();
//Prüfen, ob Wlan an ist oder Mobile daten
InternetProvider();
}
}
private void InternetProvider(){
ConnectivityManager cm =
(ConnectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
if (isConnected == false){
errorText.setText("Keine Internetverbindung!");
}else if(isConnected == true){
boolean isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
boolean isMobile = activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE;
boolean isVPN = activeNetwork.getType() == ConnectivityManager.TYPE_VPN;
boolean vpnCheck = cm.getNetworkInfo(ConnectivityManager.TYPE_VPN).isConnectedOrConnecting();
if(isWiFi == true) {
errorText.setText("WIFI");
//int networkCapabilities = NetworkCapabilities.TRANSPORT_WIFI;
//wifi_name = NetworkCapabilities.
WifiManager wifiMgr = (WifiManager) getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiInfo = wifiMgr.getConnectionInfo();
wifi_name = wifiInfo.getSSID();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 6);
wifi_stearke = "" + level;
if (vpnCheck == true){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
View view = LayoutInflater.from(getActivity()).inflate(R.layout.layout_error_dialog, getView().findViewById(R.id.layoutDialogContainer));
builder.setView(view);
((TextView) view.findViewById(R.id.textTitle)).setText("VPN ist an!");
((TextView) view.findViewById(R.id.textView_error)).setText("Du kannst kein Geld mit VPN versenden!\n\nBitte deaktiviere Sie die VPN-Verbindung.\n\nUnd probieren Sie es erneut.\n\n");
((Button) view.findViewById(R.id.buttonAction)).setText(getString(R.string.okay));
((ImageView) view.findViewById(R.id.image_error)).setImageResource(R.drawable.ic_error);
final AlertDialog alertDialog = builder.create();
alertDialog.setCancelable(false);
view.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressDialog.dismiss();
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null) {
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
}else if (vpnCheck == false){
netzwerkart = "wifi";
if(checkPermissions()){
errorText.setText("Berechtigung");
if(abgelehntPermission()){
errorText.setText("Abgelehnte Berrechtigung");
trustPermission();
}else{
WIFIINFO();
}
}else{
errorText.setText("Keine Berechtigung");
trustPermission();
}
}
}else if(isWiFi == false){
if (isMobile == true){
if (vpnCheck == true){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
View view = LayoutInflater.from(getActivity()).inflate(R.layout.layout_error_dialog, getView().findViewById(R.id.layoutDialogContainer));
builder.setView(view);
((TextView) view.findViewById(R.id.textTitle)).setText("VPN ist an!");
((TextView) view.findViewById(R.id.textView_error)).setText("Du kannst kein Geld mit VPN versenden!\n\nBitte deaktiviere die VPN-Verbinndung,\nund probieren Sie es erneut.");
((Button) view.findViewById(R.id.buttonAction)).setText(getString(R.string.okay));
((ImageView) view.findViewById(R.id.image_error)).setImageResource(R.drawable.ic_error);
final AlertDialog alertDialog = builder.create();
alertDialog.setCancelable(false);
view.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressDialog.dismiss();
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null) {
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
}else if (vpnCheck == false){
netzwerkart = "mobil";
Absenden();
}
}else if(isMobile == false){
errorText.setText("Netzwerk Fehler!");
}
}
}
}
private boolean abgelehntPermission(){
int result = ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.ACCESS_FINE_LOCATION);
return result == PackageManager.PERMISSION_DENIED;
}
protected void trustPermission(){
String[] REQUIRED_SDK_PERMISSIONS;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
REQUIRED_SDK_PERMISSIONS = new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.NEARBY_WIFI_DEVICES,
Manifest.permission.READ_EXTERNAL_STORAGE};
} else {
REQUIRED_SDK_PERMISSIONS = new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.READ_EXTERNAL_STORAGE};
}
final List<String> missingPermissions = new ArrayList<String>();
// check all required dynamic permissions
for (final String permission : REQUIRED_SDK_PERMISSIONS) {
final int result = ContextCompat.checkSelfPermission(getActivity(), permission);
if (result != PackageManager.PERMISSION_GRANTED) {
missingPermissions.add(permission);
}
}
if (!missingPermissions.isEmpty()) {
// request all missing permissions
final String[] permissions = missingPermissions
.toArray(new String[missingPermissions.size()]);
ActivityCompat.requestPermissions(getActivity(), permissions, ACCESS_FINE_LOCATION_PERMISSION_CODE);
} else {
final int[] grantResults = new int[REQUIRED_SDK_PERMISSIONS.length];
Arrays.fill(grantResults, PackageManager.PERMISSION_GRANTED);
onRequestPermissionsResult(ACCESS_FINE_LOCATION_PERMISSION_CODE, REQUIRED_SDK_PERMISSIONS,
grantResults);
}
}
private void Checkerneut(){
if(checkPermissions()){
alertDialoghinweiß.dismiss();
WIFIINFO();
}
}
private boolean checkPermissions () {
//int result = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION);
int result = 0, result1 = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
result = ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.ACCESS_FINE_LOCATION);
result1 = ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.NEARBY_WIFI_DEVICES);
}else{
result = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION);
}
return result == PackageManager.PERMISSION_GRANTED && result != PackageManager.PERMISSION_DENIED|| result == PackageManager.PERMISSION_GRANTED && result != PackageManager.PERMISSION_DENIED && result1 == PackageManager.PERMISSION_GRANTED && result1 != PackageManager.PERMISSION_DENIED;
}
@Override
public void onRequestPermissionsResult ( int requestCode, @NonNull String permissions[],
@NonNull int[] grantResults){
aLoadingDialog.dismiss();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
Log.e("JSON Filter", "Wird aufgerufen");
}
Log.e("Pre" ,"Permissionscode: " + requestCode);
switch (requestCode) {
case ACCESS_FINE_LOCATION_PERMISSION_CODE:
for (int index = permissions.length - 1; index >= 0; --index) {
if (grantResults[index] != PackageManager.PERMISSION_GRANTED) {
aLoadingDialog.dismiss();
return;
}
}
// all permissions were granted
WIFIINFO();
break;
}
}
private void WIFIINFO(){
ConnectivityManager cm = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
cm = getActivity().getSystemService(ConnectivityManager.class);
}
Network n = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
n = cm.getActiveNetwork();
}
NetworkCapabilities netCaps = cm.getNetworkCapabilities(n);
if (Build.VERSION.SDK_INT >= 30) {
wifiInfo = (WifiInfo) netCaps.getTransportInfo();
} else {
WifiManager wifiMgr = (WifiManager) getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiInfo = wifiMgr.getConnectionInfo();
}
String ssid = wifiInfo.getSSID();
Log.e("Wifiinfo", "SSID: " + ssid);
int rssi = wifiInfo.getRssi();
wifi_stearke = rssi + " dBm";
Log.e("Wifiinfo", "RSSI: " + rssi);
Absenden();
}