Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

fix adapter problem of targetSdkVersion < 23; #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public class RxPermissions {
@VisibleForTesting
Lazy<RxPermissionsFragment> mRxPermissionsFragment;

public static RxPermissions with(@NonNull final FragmentActivity activity){
return new RxPermissions(activity);
}

public static RxPermissions with(@NonNull final Fragment fragment){
return new RxPermissions(fragment);
}

public RxPermissions(@NonNull final FragmentActivity activity) {
mRxPermissionsFragment = getLazySingleton(activity.getSupportFragmentManager());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import android.annotation.TargetApi;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.PermissionChecker;
import android.util.Log;

import java.util.HashMap;
Expand Down Expand Up @@ -75,7 +77,21 @@ boolean isGranted(String permission) {
if (fragmentActivity == null) {
throw new IllegalStateException("This fragment must be attached to an activity.");
}
return fragmentActivity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;

// when targetSdkVersion < Build.VERSION_CODES.M(23), calling like below:
// ContextWrapper.checkSelfPermission or Context.checkSelfPermission ,
// it will always return PERMISSION_GRANTED
boolean permissionGranted;
if (fragmentActivity.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.M) {
// permissionGranted = PermissionChecker.checkPermission(fragmentActivity, permission,
// Binder.getCallingPid(), Binder.getCallingUid(), fragmentActivity.getPackageName())
// == PackageManager.PERMISSION_GRANTED;
permissionGranted = PermissionChecker.checkSelfPermission(fragmentActivity, permission)
== PackageManager.PERMISSION_GRANTED;
} else {
permissionGranted = fragmentActivity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
return permissionGranted;
}

@TargetApi(Build.VERSION_CODES.M)
Expand Down