Refactor check permission without supportv4 dependency

This commit is contained in:
Anthony Calosa
2020-04-05 07:02:13 +08:00
parent eeacdf6c80
commit 9f1b93373d
2 changed files with 12 additions and 12 deletions

View File

@@ -104,13 +104,6 @@
<artifactId>gdx-backend-android</artifactId> <artifactId>gdx-backend-android</artifactId>
<version>1.9.10</version> <version>1.9.10</version>
</dependency> </dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-v4</artifactId>
<version>23.1.1</version>
<scope>system</scope>
<systemPath>${pom.basedir}/libs/android-support-v4.jar</systemPath>
</dependency>
</dependencies> </dependencies>
<profiles> <profiles>

View File

@@ -25,7 +25,6 @@ import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.PowerManager; import android.os.PowerManager;
import android.provider.Settings; import android.provider.Settings;
import android.support.v4.content.ContextCompat;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.view.Gravity; import android.view.Gravity;
@@ -145,10 +144,18 @@ public class Main extends AndroidApplication {
super.onBackPressed(); super.onBackPressed();
} }
private boolean checkPermission() { private boolean checkPermission() {
int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); int pid = android.os.Process.myPid();
if (result == PackageManager.PERMISSION_GRANTED) { int uid = android.os.Process.myUid();
return true; try {
} else { int result = this.getBaseContext().checkPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, pid, uid);
//we only need the result above atm, we can free the dependency from android-support-v4 :)
//int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (result == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
} catch (NullPointerException e) {
return false; return false;
} }
} }