Skip to content

Commit

Permalink
Add support for Android 5.1 to enable Notification Permission and And…
Browse files Browse the repository at this point in the history
…roid 2.0-5.1 to enable Accessibility Permission
  • Loading branch information
adamyi committed Jul 19, 2017
1 parent ca93853 commit 940564f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
Expand Down Expand Up @@ -121,7 +122,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}

private void requestPermissions() {
if (requestedPermissions.contains(PermissionUtils.USE_ACCESSIBILITY_SERVICE)) {
// Starting API 5
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR
&& requestedPermissions.contains(PermissionUtils.USE_ACCESSIBILITY_SERVICE)) {
requestedPermissions.remove(PermissionUtils.USE_ACCESSIBILITY_SERVICE);
if (!PSAccessibilityService.enabled) {
boolean accessibilityEnabled = this.getResources().getBoolean(R.bool.accessibility_enabled);
Expand All @@ -140,7 +143,10 @@ private void requestPermissions() {
}
}
}
if (requestedPermissions.contains(PermissionUtils.USE_NOTIFICATION_SERVICE)) {

// Starting API 22
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1
&& requestedPermissions.contains(PermissionUtils.USE_NOTIFICATION_SERVICE)) {
requestedPermissions.remove(PermissionUtils.USE_NOTIFICATION_SERVICE);
if (!PSNotificationListenerService.enabled) {
boolean notificationEnabled = this.getResources().getBoolean(R.bool.notification_enabled);
Expand All @@ -158,12 +164,15 @@ private void requestPermissions() {
}
}
}
if (!requestedPermissions.isEmpty()) {
ActivityCompat.requestPermissions(PSPermissionActivity.this,
requestedPermissions.toArray(new String[requestedPermissions.size()]), requestCode);
}
else {
this.retry();

// Starting API 23
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if (!requestedPermissions.isEmpty()) {
ActivityCompat.requestPermissions(PSPermissionActivity.this,
requestedPermissions.toArray(new String[requestedPermissions.size()]), requestCode);
} else {
this.retry();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,21 @@ else if (ContextCompat.checkSelfPermission(context, p) != PackageManager.PERMISS
* @param uqi UQI instance
*/
public static void requestPermissionAndEvaluate(UQI uqi, Function<Void, Void> query) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// For Android version M and above, there is chance to request permissions at runtime
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// For Android version M and above, there is chance to request most permissions at runtime
Logging.debug("Request permissions...");
Pair<UQI, Function<Void, Void>> uqiQuery = new Pair<>(uqi, query);
int requestCode = uqiQuery.hashCode();
pendingUQIQueries.put(requestCode, uqiQuery);
Intent permissionRequest = new Intent(uqi.getContext(), PSPermissionActivity.class);
permissionRequest.putExtra(PSPermissionActivity.REQUEST_CODE, requestCode);
permissionRequest.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
uqi.getContext().startActivity(permissionRequest);
}
else {
//}
//else {
// For Android M-, we cannot request permissions at runtime
uqi.evaluate(query, false);
}
// uqi.evaluate(query, false);
//}
}
static Map<Integer, Pair<UQI, Function<Void, Void>>> pendingUQIQueries = new HashMap<>();

Expand Down

0 comments on commit 940564f

Please sign in to comment.