本文整理汇总了Java中android.support.v4.content.PermissionChecker.PERMISSION_GRANTED属性的典型用法代码示例。如果您正苦于以下问题:Java PermissionChecker.PERMISSION_GRANTED属性的具体用法?Java PermissionChecker.PERMISSION_GRANTED怎么用?Java PermissionChecker.PERMISSION_GRANTED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.support.v4.content.PermissionChecker
的用法示例。
在下文中一共展示了PermissionChecker.PERMISSION_GRANTED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkPermission
public boolean checkPermission(Context context, String... permission) {
boolean nr = true;
for (int i = 0; i < permission.length; i++) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// targetSdkVersion >= Android M, we can
// use Context#checkSelfPermission
nr = context.checkSelfPermission(permission[i])
== PackageManager.PERMISSION_GRANTED;
} else {
// targetSdkVersion < Android M, we have to use PermissionChecker
nr = PermissionChecker.checkSelfPermission(context, permission[i])
== PermissionChecker.PERMISSION_GRANTED;
}
if (!nr) {
break;
}
}
return nr;
}
示例2: onRequestPermissionsResult
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
for (int i = 0, size = permissions.length; i < size; i++) {
log("onRequestPermissionsResult " + permissions[i]);
// Find the corresponding subject
PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
if (subject == null) {
// No subject found
Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
return;
}
mSubjects.remove(permissions[i]);
boolean granted = (grantResults[i] == PackageManager.PERMISSION_GRANTED) && (PermissionChecker.checkSelfPermission(getContext(), permissions[i]) == PermissionChecker.PERMISSION_GRANTED);
subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
subject.onComplete();
}
}
示例3: checkTelephonyPermissions
@Override
public void checkTelephonyPermissions() {
if(!mRequestPermissions.isEmpty()) {
if(ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS)
!= PermissionChecker.PERMISSION_GRANTED ||
(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
!= PermissionChecker.PERMISSION_GRANTED)) {
mRequestingPermission = mRequestPermissions.get(0);
mRequestPermissions.remove(0);
PopUp.show((mRequestingPermission == EventCategories.IPC_BLE_NOTIFICATION_INCOMING_CALL)
? getString(R.string.telephony_permission)
: getString(R.string.sms_permission),
getString(R.string.permissions_needed_title),
R.drawable.message_face, R.drawable.blue_btn, PopUp.GIFF_ANIMATION_NONE,
PopUp.TYPE_CHOICE,
notificationOKHandler,
notificationCancelHandler);
}
}
}
示例4: checkTelephonyPermissions
@Override
public void checkTelephonyPermissions() {
if(!requestPermissions.isEmpty()) {
if(ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) != PermissionChecker.PERMISSION_GRANTED ||
(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PermissionChecker.PERMISSION_GRANTED)) {
requestingPermission = requestPermissions.get(0);
requestPermissions.remove(0);
PopUp.show((requestingPermission == EventCategories.IPC_BLE_NOTIFICATION_INCOMING_CALL) ? getString(R.string
.telephony_permission) : getString(R.string.sms_permission),
getString(R.string.permissions_needed_title),
R.drawable.message_face, R.drawable.blue_btn, PopUp.GIFF_ANIMATION_NONE,
PopUp.TYPE_CHOICE,
notificationOKHandler,
notificationCancelHandler);
}
}
}
示例5: applyPermission
/**
* 请求权限
*/
public void applyPermission(String[] permissions, onRequestPermissionsListener listener) {
this.listener = listener;
List<String> permissionList = new ArrayList<>();
for (String permission:permissions ) {
if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PermissionChecker.PERMISSION_GRANTED){
permissionList.add(permission);
}
}
if(permissionList.isEmpty()){
listener.onSuccess();
}else{
ActivityCompat.requestPermissions(this,permissionList.toArray(new String[permissionList.size()]), WRITE_EXTERNAL_STORAGE);
}
}
示例6: onRequestPermissionsResult
/**
* 申请权限回调
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
List<String> defeatedValue = new ArrayList<>();
switch (requestCode) {
case WRITE_EXTERNAL_STORAGE:
for (int i = 0; i < grantResults.length; i++) {
String value = permissions[i];
if(grantResults[i] != PermissionChecker.PERMISSION_GRANTED){
defeatedValue.add(value);
}
}
if(defeatedValue.isEmpty()){
listener.onSuccess();
}else{
listener.onDefeated(defeatedValue);
}
break;
}
}
示例7: onRequestPermissionsResult
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults[0] == PermissionChecker.PERMISSION_GRANTED){
subscription.add(
getLocation().subscribe(
it -> {
model.setLocation(new GeoLocation(it.getLatitude(), it.getLongitude()));
locationText.setVisibility(View.VISIBLE);
locationText.setText(getString(R.string.lat_and_lon, it.getLatitude(), it.getLongitude()));
},
Throwable::printStackTrace
)
);
}
}
示例8: allowPermission
/**
* Gives the specified permission to this app, if it is not granted
*
* @param activity the activity for accessing resources
* @param permissionName the permission name to check
* @see android.Manifest.permission
*/
public static void allowPermission(Activity activity, String permissionName) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return;
}
// if permission is still not granted
if (PermissionChecker.checkSelfPermission(activity, permissionName) != PermissionChecker.PERMISSION_GRANTED) {
// try get access for permission
ActivityCompat.requestPermissions(activity,
new String[]{
permissionName
}, PERMISSION_GRANTED_CODE);
} else {
Log.i(TAG, "Permission " + permissionName + " is granted");
}
}
示例9: onRequestPermissionsResult
/**
* Callback for permission requests. If external storage permissions are granted, this will
* restart the application.
*
* @param context The Context
* @param requestCode The request code
* @param permissions Array of permissions requested
* @param grantResults Array of results of the permission requests
*/
public static void onRequestPermissionsResult(@NonNull Context context, int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
switch(requestCode) {
case REQUEST_LOCATION:
for(int i = 0; i < grantResults.length; i++) {
if(!Manifest.permission.ACCESS_COARSE_LOCATION.equals(permissions[i])) {
continue;
}
if(grantResults[i] == PermissionChecker.PERMISSION_GRANTED) {
PreferenceManager.getDefaultSharedPreferences(context).edit()
.putBoolean(FlavordexApp.PREF_DETECT_LOCATION, true).apply();
}
}
break;
}
}
示例10: show
/**
* 显示窗口
*/
public void show() {
int alertWindowPermission = PermissionChecker.checkSelfPermission(mContext, Manifest.permission.SYSTEM_ALERT_WINDOW);
if (alertWindowPermission == PermissionChecker.PERMISSION_GRANTED) {
mWindowManager.addView(mWindowView, mWindowLayoutParams);
isShow = true;
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Settings.canDrawOverlays(mContext)) {
mWindowManager.addView(mWindowView, mWindowLayoutParams);
isShow = true;
} else {
Toast.makeText(mContext, "没有显示悬浮窗权限,请设置允许显示悬浮窗!", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(mContext, "没有显示悬浮窗权限,请设置允许显示悬浮窗!", Toast.LENGTH_SHORT).show();
}
}
}
示例11: parseRequestResult
/**
* Called when there is a new response for a Android Manifest Permission request
*
* @param requestCode received.
* @param permissions the Android Manifest Permissions that were requested
* @param grantResults the grant result for each permission
* @return the list of Android Manifest Permissions that were declined by the user.
*/
public List<String> parseRequestResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode != this.lastRequestCode) {
Log.d(TAG, String.format("The received Request Code doesn't match the expected one. Was %d but expected %d", requestCode, this.lastRequestCode));
return Arrays.asList(permissions);
} else if (permissions.length == 0 && grantResults.length == 0) {
Log.w(TAG, "All the required permissions were declined by the user.");
return Arrays.asList(permissions);
}
List<String> declinedPermissions = new ArrayList<>();
for (int i = 0; i < permissions.length; i++) {
if (grantResults[i] != PermissionChecker.PERMISSION_GRANTED) {
declinedPermissions.add(permissions[i]);
}
}
if (!declinedPermissions.isEmpty()) {
Log.w(TAG, String.format("%d permissions were explicitly declined by the user.", declinedPermissions.size()));
}
return declinedPermissions;
}
示例12: doPermissionsRequest
public void doPermissionsRequest(@NonNull InterstitialPoint returnTo, String[] permissions) {
boolean havePermissions = true;
for (String permission : permissions) {
int checkResult = ActivityCompat.checkSelfPermission(this, permission);
if (checkResult != PermissionChecker.PERMISSION_GRANTED) {
havePermissions = false;
break;
}
}
if (!havePermissions) {
int code = 0;
permissionsPoint = returnTo;
ActivityCompat.requestPermissions(this, permissions, code);
} else {
returnTo.returnToWork(true);
}
}
示例13: onCreate
@Override
protected void onCreate(final Bundle b) {
super.onCreate(b);
setResult(RESULT_CANCELED);
if (Build.VERSION.SDK_INT >= 23 && PermissionChecker
.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PermissionChecker.PERMISSION_GRANTED && PermissionChecker
.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
PermissionChecker.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_STORAGE_PERMISSION);
} else {
start();
}
}
示例14: onCreate
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (PermissionChecker
.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) !=
PermissionChecker.PERMISSION_GRANTED || PermissionChecker
.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PermissionChecker.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(Map.this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSIONS);
} else {
showMap();
}
}
示例15: loadInBackground
@Override
public List<Album> loadInBackground() {
ArrayList<Album> albums = new ArrayList<>();
if (PermissionChecker.checkCallingOrSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED) {
Cursor musicCursor = getContext().getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, datacol, Where, selectionargs, sortorder);
if (musicCursor != null && musicCursor.moveToFirst()) {
int titleColumn = musicCursor.getColumnIndex(MediaStore.Audio.AlbumColumns.ALBUM);
int idColumn = musicCursor.getColumnIndex(BaseColumns._ID);
int artistColumn = musicCursor.getColumnIndex(MediaStore.Audio.AlbumColumns.ARTIST);
int numOfSongsColumn = musicCursor.getColumnIndex(MediaStore.Audio.AlbumColumns.NUMBER_OF_SONGS);
int albumfirstColumn = musicCursor.getColumnIndex(MediaStore.Audio.AlbumColumns.FIRST_YEAR);
do {
String albumName = musicCursor.getString(titleColumn);
long albumId = musicCursor.getLong(idColumn);
String artistName = musicCursor.getString(artistColumn);
int year = musicCursor.getInt(albumfirstColumn);
int no = musicCursor.getInt(numOfSongsColumn);
Album album = new Album();
/**
* Setting Album Metadata
*/
album.setArtistName(artistName);
album.setAlbumName(albumName);
album.setId(albumId);
album.setTrackCount(no);
album.setYear(year);
albums.add(album);
} while (musicCursor.moveToNext());
musicCursor.close();
}
if (musicCursor == null) {
return Collections.emptyList();
}
return albums;
} else {
return null;
}
}