Add message about denied permissions

This commit is contained in:
xynngh 2020-05-06 13:54:05 +04:00
parent cf32cf41cb
commit 9eed9a1a58
3 changed files with 26 additions and 1 deletions

View File

@ -75,7 +75,7 @@ public class MainActivity extends AppCompatActivity {
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// TODO: handle
PermissionHelper.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
loadCallLog();
}

View File

@ -4,7 +4,9 @@ import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@ -41,6 +43,27 @@ public class PermissionHelper {
}
}
public static void onRequestPermissionsResult(@NonNull Context context, int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
boolean denied = false;
if (permissions.length == 0) {
denied = true;
} else {
for (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
denied = true;
break;
}
}
}
if (denied) {
Toast.makeText(context, R.string.denied_permissions_message, Toast.LENGTH_SHORT).show();
}
}
public static boolean havePermission(Context context, String permission) {
return ContextCompat.checkSelfPermission(context, permission)
== PackageManager.PERMISSION_GRANTED;

View File

@ -50,6 +50,8 @@
<string name="title_activity_reviews">Reviews</string>
<string name="reviews_loading">Loading reviews…</string>
<string name="denied_permissions_message">Some functionality may not work due to denied permissions</string>
<string name="general_settings">General settings</string>
<string name="no_main_db_title">Download main database</string>