当前位置: 首页>>代码示例>>Java>>正文


Java Activity.checkSelfPermission方法代码示例

本文整理汇总了Java中android.app.Activity.checkSelfPermission方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.checkSelfPermission方法的具体用法?Java Activity.checkSelfPermission怎么用?Java Activity.checkSelfPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Activity的用法示例。


在下文中一共展示了Activity.checkSelfPermission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: askForPermissons

import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons() {
    Activity activity = getParentActivity();
    if (activity == null) {
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        permissons.add(Manifest.permission.READ_CONTACTS);
        permissons.add(Manifest.permission.WRITE_CONTACTS);
        permissons.add(Manifest.permission.GET_ACCOUNTS);
    }
    if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        permissons.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        permissons.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    String[] items = permissons.toArray(new String[permissons.size()]);
    activity.requestPermissions(items, 1);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:20,代码来源:DialogsActivity.java

示例2: getPermission

import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(M)
static private void getPermission(String[] permissions,Activity activity) {
    if(Build.VERSION.SDK_INT>=23) {
        ArrayList<String> preToDo = new ArrayList<>();
        boolean tip = false;
        for (String pre : permissions) {
            if (activity.checkSelfPermission(pre) != PackageManager.PERMISSION_GRANTED) {
                preToDo.add(pre);
                if (activity.shouldShowRequestPermissionRationale(pre)) {
                    tip = true;
                }
            }
        }
        if (preToDo.size() == 0)
            return;
        if (tip)
            showToast(sContext.getString(R.string.permissions_need));
        activity.requestPermissions(preToDo.toArray(new String[preToDo.size()]), 0);
    }
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:21,代码来源:LaunchService.java

示例3: validatePermissions

import android.app.Activity; //导入方法依赖的package包/类
public static boolean validatePermissions(final Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            return true;
        } else {
            AlertDialog.Builder alert = new AlertDialog.Builder(activity);
            alert.setTitle("Permission Error");
            alert.setMessage("Grant permissions in the next dialog and retry download.");
            alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                    ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
                }
            });
            alert.show();
            return false;
        }
    } else {
        return true;
    }
}
 
开发者ID:skyguy126,项目名称:Xposed-SoundCloudDownloader,代码行数:22,代码来源:Shared.java

示例4: isContactsPermissionGranted

import android.app.Activity; //导入方法依赖的package包/类
private static boolean isContactsPermissionGranted(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(READ_CONTACTS)
                == PackageManager.PERMISSION_GRANTED) {
            Timber.d("Permission is granted");
            return true;
        } else {

            Timber.d("Permission is revoked");
            ActivityCompat.requestPermissions(activity,
                    new String[]{READ_CONTACTS},
                    activity.getResources().getInteger(R.integer.contacts_request));
            return false;
        }
    } else { //permission is automatically granted on sdk<23 upon installation
        Timber.d("Permission is granted");
        return true;
    }
}
 
开发者ID:sciage,项目名称:FinalProject,代码行数:20,代码来源:ActivityUtils.java

示例5: maybeRequestReadExternalStoragePermission

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Checks whether it's necessary to request the {@link permission#READ_EXTERNAL_STORAGE}
 * permission read the specified {@link Uri}s, requesting the permission if necessary.
 *
 * @param activity The host activity for checking and requesting the permission.
 * @param uris {@link Uri}s that may require {@link permission#READ_EXTERNAL_STORAGE} to read.
 * @return Whether a permission request was made.
 */
@TargetApi(23)
public static boolean maybeRequestReadExternalStoragePermission(Activity activity, Uri... uris) {
  if (Util.SDK_INT < 23) {
    return false;
  }
  for (Uri uri : uris) {
    if (Util.isLocalFileUri(uri)) {
      if (activity.checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
          != PackageManager.PERMISSION_GRANTED) {
        activity.requestPermissions(new String[] {permission.READ_EXTERNAL_STORAGE}, 0);
        return true;
      }
      break;
    }
  }
  return false;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:26,代码来源:Util.java

示例6: isReadStoragePermissionGranted

import android.app.Activity; //导入方法依赖的package包/类
private static boolean isReadStoragePermissionGranted(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Timber.d("Permission is granted");
            return true;
        } else {

            Timber.d("Permission is revoked");
            ActivityCompat.requestPermissions(activity,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    activity.getResources().getInteger(R.integer.read_external_storage_request));
            return false;
        }
    } else { //permission is automatically granted on sdk<23 upon installation
        Timber.d("Permission is granted");
        return true;
    }
}
 
开发者ID:sciage,项目名称:FinalProject,代码行数:20,代码来源:ActivityUtils.java

示例7: findPermissionResult

import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(value = Build.VERSION_CODES.M)
private static List<MPermissionResultEnum> findPermissionResult(Activity activity, String... permissions) {
    boolean overM = isOverMarshmallow();
    List<MPermissionResultEnum> result = new ArrayList<>();
    for (String p : permissions) {
        if (overM) {
            if (activity.checkSelfPermission(p) == PackageManager.PERMISSION_GRANTED) {
                result.add(MPermissionResultEnum.GRANTED);
            } else {
                if (!activity.shouldShowRequestPermissionRationale(p)) {
                    result.add(MPermissionResultEnum.DENIED_NEVER_ASK_AGAIN);
                } else {
                    result.add(MPermissionResultEnum.DENIED);
                }
            }
        } else {
            result.add(MPermissionResultEnum.GRANTED);
        }
    }

    return result;
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:23,代码来源:BaseMPermission.java

示例8: isAudioPermissionGranted

import android.app.Activity; //导入方法依赖的package包/类
private static boolean isAudioPermissionGranted(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(Manifest.permission.RECORD_AUDIO)
                == PackageManager.PERMISSION_GRANTED) {
            Timber.d("Permission is granted");
            return true;
        } else {

            Timber.d("Permission is revoked");
            ActivityCompat.requestPermissions(activity,
                    new String[]{Manifest.permission.RECORD_AUDIO},
                    activity.getResources().getInteger(R.integer.recorder_request));
            return false;
        }
    } else { //permission is automatically granted on sdk<23 upon installation
        Timber.d("Permission is granted");
        return true;
    }
}
 
开发者ID:sciage,项目名称:FinalProject,代码行数:20,代码来源:ActivityUtils.java

示例9: isWritePermissionGranted

import android.app.Activity; //导入方法依赖的package包/类
private static boolean isWritePermissionGranted(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(WRITE_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Timber.d("Permission is granted");
            return true;
        } else {

            Timber.d("Permission is revoked");
            ActivityCompat.requestPermissions(activity,
                    WRITE_PERM,
                    INT_DELETE_PICTURE_PERM);
            return false;
        }
    } else { //permission is automatically granted on sdk<23 upon installation
        Timber.d("Permission is granted");
        return true;
    }
}
 
开发者ID:sciage,项目名称:FinalProject,代码行数:20,代码来源:ActivityUtils.java

示例10: hasStorageReadPermission

import android.app.Activity; //导入方法依赖的package包/类
private static boolean hasStorageReadPermission(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
                activity.checkSelfPermission(READ_EXTERNAL_STORAGE) == PERMISSION_GRANTED;
    }
    return true;
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:8,代码来源:PathChecker.java

示例11: getDeniedPermissions

import android.app.Activity; //导入方法依赖的package包/类
/**
 * 获取请求权限中需要授权的权限
 */
@TargetApi(Build.VERSION_CODES.M)
private static String[] getDeniedPermissions(Activity activity, String[] permissions) {
    List<String> deniedPermissions = new ArrayList();
    try {
        for (String permission : permissions) {
            if (activity.checkSelfPermission(permission) == PackageManager.PERMISSION_DENIED) {
                deniedPermissions.add(permission);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return deniedPermissions.toArray(new String[deniedPermissions.size()]);
}
 
开发者ID:lennyup,项目名称:react-native-udesk,代码行数:18,代码来源:XPermissionUtils.java

示例12: hasPermission

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Returns true if the Activity has access to a all given permission.
 */
public static boolean hasPermission(Activity activity, String[] permissions) {
    for (String permission : permissions) {
        if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
    }
    return true;
}
 
开发者ID:Vinetos,项目名称:Hello-Music-droid,代码行数:12,代码来源:Nammu.java

示例13: checkPermissionManuel

import android.app.Activity; //导入方法依赖的package包/类
public static int checkPermissionManuel(Activity mActivity, String permission, int requestCode){
    int hasWriteContactsPermission = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        hasWriteContactsPermission = mActivity.checkSelfPermission(permission);

    }else{
        hasWriteContactsPermission = 0;
    }
    return hasWriteContactsPermission;
}
 
开发者ID:barisatalay,项目名称:thermalprinterhelper,代码行数:11,代码来源:UtilsPermission.java

示例14: isGrantExternalRW

import android.app.Activity; //导入方法依赖的package包/类
/**
 * 6.0以上权限
 *
 * @param activity
 * @return
 */
public static boolean isGrantExternalRW(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && activity.checkSelfPermission(
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        activity.requestPermissions(new String[]{
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
        }, 1);

        return false;
    }

    return true;
}
 
开发者ID:NICOLITE,项目名称:HutHelper,代码行数:21,代码来源:CommUtil.java

示例15: requestPermission

import android.app.Activity; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.M)
    public static void requestPermission(Activity activity, final String permission,
                                         final int reqCode) {
//        if (checkSelfPermission(Manifest.permission.READ_CONTACTS) !=
//                PackageManager.PERMISSION_GRANTED) {
//
//            requestPermissions(new String[]{Manifest.permission.READ_CONTACTS},
//                    REQUEST_CONTACT_PERMISSION);
//        }
        if (activity.checkSelfPermission(permission) !=
                PackageManager.PERMISSION_GRANTED) {

            activity.requestPermissions(new String[]{permission}, reqCode);
        }
    }
 
开发者ID:shashi2459,项目名称:notify-me,代码行数:16,代码来源:Utils.java


注:本文中的android.app.Activity.checkSelfPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。