本文整理汇总了Java中android.app.Activity.requestPermissions方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.requestPermissions方法的具体用法?Java Activity.requestPermissions怎么用?Java Activity.requestPermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Activity
的用法示例。
在下文中一共展示了Activity.requestPermissions方法的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);
}
示例2: getLocation
import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
public static void getLocation(final Activity mActivity, final int PERMISSION_REQUEST_CODE)
{
List<String> permissionsNeeded = new ArrayList<>();
List<String> permissionsList = new ArrayList<>();
if (!addPermission(mActivity,permissionsList, android.Manifest.permission.ACCESS_FINE_LOCATION))
permissionsNeeded.add(mActivity.getResources().getString(R.string.GPS));
if (permissionsList.size() > 0)
{
mActivity.requestPermissions(permissionsList.toArray(new String[permissionsList.size()]), PERMISSION_REQUEST_CODE);
}
}
示例3: getOTP
import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
static void getOTP(final Activity mActivity, final int PERMISSION_REQUEST_CODE)
{
List<String> permissionsNeeded = new ArrayList<>();
List<String> permissionsList = new ArrayList<>();
if (!addPermission(mActivity,permissionsList, android.Manifest.permission.READ_SMS))
permissionsNeeded.add(mActivity.getResources().getString(R.string.READ_SMS));
if (permissionsList.size() > 0)
{
mActivity.requestPermissions(permissionsList.toArray(new String[permissionsList.size()]), PERMISSION_REQUEST_CODE);
}
}
示例4: 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;
}
示例5: askForPermission
import android.app.Activity; //导入方法依赖的package包/类
public static void askForPermission(Activity activity, String[] permissions, PermissionCallback permissionCallback) {
if (permissionCallback == null) {
return;
}
if (hasPermission(activity, permissions)) {
permissionCallback.permissionGranted();
return;
}
PermissionRequest permissionRequest = new PermissionRequest(new ArrayList<String>(Arrays.asList(permissions)), permissionCallback);
permissionRequests.add(permissionRequest);
activity.requestPermissions(permissions, permissionRequest.getRequestCode());
}
示例6: requestPermission
import android.app.Activity; //导入方法依赖的package包/类
public static void requestPermission(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.shouldShowRequestPermissionRationale(PERMISSION_CAMERA)
|| activity.shouldShowRequestPermissionRationale(PERMISSION_STORAGE)) {
Toast.makeText(activity, "Need camera and storage permissions to continue",
Toast.LENGTH_LONG).show();
}
activity.requestPermissions(new String[]{PERMISSION_CAMERA,
PERMISSION_STORAGE}, PERMISSIONS_REQUEST);
}
}
示例7: 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;
}
示例8: 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);
}
}
示例9: requestPermissionsAgain
import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
public static void requestPermissionsAgain(Activity activity, String[] permissions,
int requestCode) {
try {
activity.requestPermissions(permissions, requestCode);
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: requestSMSPermission
import android.app.Activity; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.M)
public static void requestSMSPermission(@NonNull Activity activity) {
final String permission = Manifest.permission.RECEIVE_SMS;
int hasSpecificPermission = ContextCompat.checkSelfPermission(activity, permission);
if (hasSpecificPermission != PackageManager.PERMISSION_GRANTED
&& !activity.shouldShowRequestPermissionRationale(permission)) {
activity.requestPermissions(new String[]{permission},
REQUEST_CODE_ASK_PERMISSIONS);
}
}
示例11: requestPermissions
import android.app.Activity; //导入方法依赖的package包/类
@Nullable
public static HttpResponse requestPermissions(@NonNull String ... permissions) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Activity activity = getCurrentActivity();
if (activity != null && !checkSelfPermissions(activity, permissions)) {
activity.requestPermissions(permissions, 0);
return new HttpResponse(new ErrorPage("This module require additional permissions. Please allow it on your smartphone and reload this page.").toHtml());
}
}
return null;
}
示例12: requestContactPermission
import android.app.Activity; //导入方法依赖的package包/类
static void requestContactPermission(Activity activity) {
activity.requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}
, CONTACT_REQUEST_CODE);
}
示例13: requestWriteStoragePermission
import android.app.Activity; //导入方法依赖的package包/类
public static void requestWriteStoragePermission(Activity activity) {
if (Utils.hasMarshmallow()) {
activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_PERMISSION_WRITE_STORAGE);
}
}
示例14: requestReadExternalStoragePermission
import android.app.Activity; //导入方法依赖的package包/类
public static void requestReadExternalStoragePermission(Activity activity) {
if (Utils.hasMarshmallow()) {
activity.requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_PERMISSION_READ_EXTARNAL_STORAGE);
}
}
示例15: requestPermissions
import android.app.Activity; //导入方法依赖的package包/类
public static void requestPermissions(Context context) {
Activity activity = (Activity) context;
if (!checkPermissions(context)) {
activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, AppPreferences.CODE_PERMISSION);
}
}