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


Java Activity.requestPermissions方法代码示例

本文整理汇总了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);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:20,代码来源:DialogsActivity.java

示例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);
        }
}
 
开发者ID:yash786agg,项目名称:GPS,代码行数:17,代码来源:AcessLocation.java

示例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);
    }
}
 
开发者ID:yash786agg,项目名称:Read_SMS,代码行数:17,代码来源:Acess_SMS.java

示例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;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:26,代码来源:Util.java

示例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());
}
 
开发者ID:Vinetos,项目名称:Hello-Music-droid,代码行数:14,代码来源:Nammu.java

示例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);
    }
}
 
开发者ID:deepenai,项目名称:deepenlib-android-sample,代码行数:12,代码来源:PermissionUtil.java

示例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;
}
 
开发者ID:NICOLITE,项目名称:HutHelper,代码行数:21,代码来源:CommUtil.java

示例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);
        }
    }
 
开发者ID:shashi2459,项目名称:notify-me,代码行数:16,代码来源:Utils.java

示例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();
    }
}
 
开发者ID:lennyup,项目名称:react-native-udesk,代码行数:10,代码来源:XPermissionUtils.java

示例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);
    }
}
 
开发者ID:adorsys,项目名称:sms-parser-android,代码行数:11,代码来源:SmsTool.java

示例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;
}
 
开发者ID:bartwell,项目名称:ultra-debugger,代码行数:12,代码来源:CommonUtils.java

示例12: requestContactPermission

import android.app.Activity; //导入方法依赖的package包/类
static void requestContactPermission(Activity activity) {

        activity.requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}
                , CONTACT_REQUEST_CODE);
    }
 
开发者ID:enricocid,项目名称:EasyOne,代码行数:6,代码来源:PermissionUtils.java

示例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);
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:7,代码来源:AppPerms.java

示例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);
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:7,代码来源:AppPerms.java

示例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);
    }
}
 
开发者ID:dkanada,项目名称:OpenAPK,代码行数:7,代码来源:OtherUtils.java


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