Browse Source

Änderungen im Manifest und in der MainActivity.java: Ergänzung zweier Internet-Permissions inklusive Abfrage dieser, wenn der Button "connectionButton" betätigt wird.

Allerdings: Internet Permission wird automatisch erteilt, Abfrage ist eigentlich sinnlos.
DoNotMergeAddInternetPermission
Maria Nutz 1 year ago
parent
commit
e1b822aa13

+ 3
- 0
app/src/main/AndroidManifest.xml View File

@@ -4,6 +4,9 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />


<uses-feature android:name="android.hardware.camera"/>


+ 33
- 1
app/src/main/java/com/example/greenwatch/MainActivity.java View File

@@ -1,16 +1,23 @@
package com.example.greenwatch;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.Manifest;

import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
import com.example.greenwatch.adapters.DeviceListAdapter;
@@ -29,6 +36,8 @@ public class MainActivity extends AppCompatActivity {
private Button connectionButton;
private MainActivityViewModel mMainActivityViewModel;

private static final int REQUEST_PERMISSION_INTERNET = 123;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -127,7 +136,14 @@ public class MainActivity extends AppCompatActivity {
connectionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openConnectionActivity();
if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CHANGE_WIFI_MULTICAST_STATE) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.INTERNET, Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.CHANGE_WIFI_MULTICAST_STATE}, REQUEST_PERMISSION_INTERNET);
} else {
openConnectionActivity();
}
}
});
}
@@ -157,4 +173,20 @@ public class MainActivity extends AppCompatActivity {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", true, "Audio", 10);
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSION_INTERNET) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Berechtigungen wurden gewährt
Toast.makeText(this, "Berechtigungen gewährt", Toast.LENGTH_SHORT).show();
openConnectionActivity();
} else {
// Berechtigungen wurden nicht gewährt
Toast.makeText(this, "Berechtigungen nicht gewährt", Toast.LENGTH_SHORT).show();
}
}
}


}

Loading…
Cancel
Save