Browse Source

permission

Evgeny Polivanov 2 years ago
parent
commit
92b1dfdc0f
2 changed files with 25 additions and 5 deletions
  1. 1 2
      README.md
  2. 24 3
      app/src/main/java/com/drinkertea/test2smack/MainActivity.java

+ 1 - 2
README.md

@@ -1,5 +1,4 @@
 # Android XMPP Chat
 - Test mobile application for instant messaging via XMPP protocol.
 - **Download** the application from the <a href="https://github.com/WorldOfPets/test_apk_file/raw/master/app-debug.apk">**link**</a>.
-- The application has a built-in auto-update feature. Download, don't worry!
-- You may need to manually allow the app to access the storage. This is a temporary issue that will be resolved soon.
+- The application has a built-in auto-update feature. Download, don't worry!

+ 24 - 3
app/src/main/java/com/drinkertea/test2smack/MainActivity.java

@@ -1,10 +1,16 @@
 package com.drinkertea.test2smack;
 
+import androidx.annotation.NonNull;
 import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
 
+import android.Manifest;
+import android.app.Activity;
 import android.app.Dialog;
 import android.app.ProgressDialog;
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.os.Handler;
 import android.view.View;
@@ -111,8 +117,23 @@ public class MainActivity extends AppCompatActivity {
     }
 
     public void updateApp(View view) throws Exception{
-        String BASEURL = "https://github.com/WorldOfPets/test_apk_file/raw/master/app-debug.apk";
-        DownloadApk downloadApk = new DownloadApk(MainActivity.this);
-        downloadApk.startDownloadingApk(BASEURL);
+        String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.REQUEST_INSTALL_PACKAGES};
+        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) ==
+                PackageManager.PERMISSION_GRANTED){
+            String BASEURL = "https://github.com/WorldOfPets/test_apk_file/raw/master/app-debug.apk";
+            DownloadApk downloadApk = new DownloadApk(MainActivity.this);
+            downloadApk.startDownloadingApk(BASEURL);
+        } else {
+            ActivityCompat.requestPermissions(
+                this,
+                permissions,
+                1
+            );
+        }
+    }
+
+    @Override
+    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
     }
 }