mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 05:48:23 +03:00
Request needed permissions
This commit is contained in:
parent
cdc92d77a4
commit
07ac77f018
2 changed files with 20 additions and 10 deletions
|
@ -94,6 +94,7 @@ public class Database {
|
|||
protected String doInBackground(String... strings) {
|
||||
String url = strings[0];
|
||||
File out = new File(strings[1]);
|
||||
publishProgress("Downloading " + url);
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setConnectTimeout(45000);
|
||||
|
@ -118,19 +119,18 @@ public class Database {
|
|||
}
|
||||
|
||||
fileOutputStream.close();
|
||||
publishProgress("Successfully downloaded " + url + "\n");
|
||||
publishProgress("Successfully downloaded\n");
|
||||
} else {
|
||||
publishProgress("File not downloaded " + res + "\n");
|
||||
publishProgress("File not downloaded, response code " + res + "\n");
|
||||
}
|
||||
} else {
|
||||
publishProgress("File not changed " + url + "\n");
|
||||
publishProgress("File not changed\n");
|
||||
}
|
||||
connection.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
publishProgress("Failed to download file from " + url + "\n");
|
||||
publishProgress("Failed to download, check logcat\n");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -138,10 +138,5 @@ public class Database {
|
|||
protected void onProgressUpdate(String... progress) {
|
||||
log.append(progress[0] + "\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package us.spotco.malwarescanner;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
|
@ -18,6 +23,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
private boolean scanInternal = true;
|
||||
private boolean scanExternal = false;
|
||||
|
||||
private static final int REQUEST_PERMISSION_EXTERNAL_STORAGE = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -48,6 +55,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
requestPermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,6 +65,12 @@ public class MainActivity extends AppCompatActivity {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void requestPermissions() {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_PERMISSION_EXTERNAL_STORAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue