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


Java Fragment.requestPermissions方法代码示例

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


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

示例1: checkPermission

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private boolean checkPermission(Fragment fragment){
    int check=ActivityCompat.checkSelfPermission(fragment.getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if(check!= PackageManager.PERMISSION_GRANTED){
        fragment.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},REQUEST_CODE);
        return false;
    }
    return true;
}
 
开发者ID:zillachan,项目名称:AndZilla,代码行数:9,代码来源:FileLog.java

示例2: requestPermission

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public void requestPermission(Fragment fragment, int requestCode, SinglePermissionListener listener, String... permissions) {
    if (ArrayUtils.isEmpty(permissions) || listener == null || fragment.getActivity() == null) {
        return;
    }
    this.currentRequestCode = requestCode;
    this.singlePermissionListener = listener;
    notHasPermission = notHasPermission(fragment.getActivity(), permissions);
    //check if permission is granted
    if (!ArrayUtils.isEmpty(notHasPermission)) {
        String[] showRequestPermission = showRequestPermission(fragment.getActivity(), permissions);
        if (!ArrayUtils.isEmpty(showRequestPermission)) {
            showExplanation(fragment.getActivity(), permissions, fragment, true);
        } else {
            fragment.requestPermissions(permissions, currentRequestCode);
        }
    } else {
        singlePermissionListener.onPermissionGranted(currentRequestCode, permissions);
    }
}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:20,代码来源:SinglePermission.java

示例3: requestPermissions

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
 * Request a set of permissions, showing rationale if the system requests it.
 *
 * @param fragment {@link Fragment} requesting permissions. Should override {@link
 *                 Fragment#onRequestPermissionsResult(int, String[], int[])}.
 * @see #requestPermissions(Activity, String, int, int, int, String...)
 */
@SuppressLint("NewApi")
public static void requestPermissions(@NonNull Fragment fragment,
                                      @NonNull String rationale,
                                      @StringRes int positiveButton,
                                      @StringRes int negativeButton,
                                      int requestCode,
                                      @NonNull String... perms) {
    if (hasPermissions(fragment.getContext(), perms)) {
        notifyAlreadyHasPermissions(fragment, requestCode, perms);
        return;
    }

    if (shouldShowRationale(fragment, perms)) {
        RationaleDialogFragmentCompat
                .newInstance(positiveButton, negativeButton, rationale, requestCode, perms)
                .show(fragment.getChildFragmentManager(), DIALOG_TAG);
    } else {
        fragment.requestPermissions(perms, requestCode);
    }
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:28,代码来源:EasyPermissions.java

示例4: checkWriteStoragePermission

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public static boolean checkWriteStoragePermission(Fragment fragment) {

        int writeStoragePermissionState =
                ContextCompat.checkSelfPermission(fragment.getContext(), WRITE_EXTERNAL_STORAGE);

        boolean writeStoragePermissionGranted = writeStoragePermissionState == PackageManager.PERMISSION_GRANTED;

        if (!writeStoragePermissionGranted) {
            fragment.requestPermissions(PermissionsConstant.PERMISSIONS_EXTERNAL_WRITE,
                    PermissionsConstant.REQUEST_EXTERNAL_WRITE);
        }
        return writeStoragePermissionGranted;
    }
 
开发者ID:malijie,项目名称:PhotoPicker-master,代码行数:14,代码来源:PermissionsUtils.java

示例5: requestPermissionsIfNecessaryForResult

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
 * This method should be used to execute a {@link PermissionsResultAction} for the array
 * of permissions passed to this method. This method will request the permissions if
 * they need to be requested (i.e. we don't have permission yet) and will add the
 * PermissionsResultAction to the queue to be notified of permissions being granted or
 * denied. In the case of pre-Android Marshmallow, permissions will be granted immediately.
 * The Fragment variable is used, but if {@link Fragment#getActivity()} returns null, this method
 * will fail to work as the activity reference is necessary to check for permissions.
 *
 * @param fragment    the fragment necessary to request the permissions.
 * @param permissions the list of permissions to request for the {@link PermissionsResultAction}.
 * @param action      the PermissionsResultAction to notify when the permissions are granted or denied.
 */
@SuppressWarnings("unused")
public synchronized void requestPermissionsIfNecessaryForResult(@NonNull Fragment fragment,
    @NonNull String[] permissions,
    @Nullable PermissionsResultAction action) {
  Activity activity = fragment.getActivity();
  if (activity == null) {
    return;
  }
  addPendingAction(permissions, action);
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    doPermissionWorkBeforeAndroidM(activity, permissions, action);
  } else {
    List<String> permList = getPermissionsListToRequest(activity, permissions, action);
    if (permList.isEmpty()) {
      //if there is no permission to request, there is no reason to keep the action int the list
      removePendingAction(action);
    } else {
      String[] permsToRequest = permList.toArray(new String[permList.size()]);
      mPendingRequests.addAll(permList);
      fragment.requestPermissions(permsToRequest, 1);
    }
  }
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:37,代码来源:PermissionsManager.java

示例6: checkOrRequest

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
 * @return true if all permissions is granted
 */
public static boolean checkOrRequest(@NonNull Fragment fragment, int requestCode, String... permissions) {
    if (!check(fragment.getContext(), permissions)) {
        fragment.requestPermissions(permissions, requestCode);
        return false;
    } else return true;
}
 
开发者ID:Cleveroad,项目名称:AdaptiveTableLayout,代码行数:10,代码来源:PermissionHelper.java

示例7: getLocation

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public void getLocation(Fragment fragment) {
    this.fragment = fragment;
    boolean locationPermissionFlag = util.checkPermission(locationPermissions,
            activity);
    if (locationPermissionFlag) {
        fragment.requestPermissions(locationPermissions, Configure.LOCATION_PERMISSION_CODE);
    }else{
        locationManager = (LocationManager) activity.getSystemService(Context.
                LOCATION_SERVICE);
        String provider;
        List<String> providerList = locationManager.getProviders(true);
        if (providerList.contains(LocationManager.GPS_PROVIDER)) {
            provider = LocationManager.GPS_PROVIDER;
        } else if (providerList.contains(LocationManager.NETWORK_PROVIDER)) {
            provider = LocationManager.NETWORK_PROVIDER;
        } else {
            Toast.makeText(activity, "请连接网络或打开GPS",
                    Toast.LENGTH_LONG).show();
            return;
        }
        Location location = locationManager.getLastKnownLocation(provider);
        locationManager.requestLocationUpdates(provider, 2000, 10, this);
        if (location != null) {
            getLocation(location);
        }
    }
}
 
开发者ID:victorySSS,项目名称:readingNotes,代码行数:28,代码来源:LocationUtil.java

示例8: _requestPermissions

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private static boolean _requestPermissions(Object object, String[] permissions, int request_contacts) {
    if (permissions.length < 1) {
        return false;
    }
    if (object instanceof Activity) {
        if (shouldShowRequestPermissionRationale((Activity) object, permissions))
            return false;
    }
    // Verify that each required permission has been granted, otherwise return false.
    for (String p : permissions) {
        if (object instanceof Activity) {
            //PERMISSION_GRANTED if you have the permission, or PERMISSION_DENIED if not.
            if (ActivityCompat.checkSelfPermission((Activity) object, p) != PackageManager.PERMISSION_GRANTED) {
                // Should we show an explanation?
                ActivityCompat.requestPermissions((Activity) object, permissions, request_contacts);
                return false;
            }
        } else if (object instanceof Fragment) {
            Fragment fragment = (Fragment) object;
            if (ContextCompat.checkSelfPermission(fragment.getActivity(), p) != PackageManager.PERMISSION_GRANTED) {
                fragment.requestPermissions(permissions, request_contacts);
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:28,代码来源:PermissionUtil.java

示例9: reqFragmentPermission

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public static void reqFragmentPermission(Fragment fragment, final Activity mContext, final String Text, int PermissionCode, String Permission) {
    if (!fragment.shouldShowRequestPermissionRationale(Permission)) {
        fragment.requestPermissions(new String[]{Permission}, PermissionCode);
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setCancelable(false);
        builder.setTitle("Permission");
        builder.setMessage("You needs to Grant Access " + Text + " From Settings >> AppInfo >> Permissions For Using Application");
        builder.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                //
                dialog.dismiss();
                String packageName = Utils.getAppPackageName(mContext);
                try {
                    //Open the specific App Info page:
                    Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    intent.setData(Uri.parse("package:" + packageName));
                    mContext.startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    //e.printStackTrace();
                    Toast.makeText(mContext, "You need to Grant Access " + Text + " From Settings >> AppInfo >> Permissions For Using Application", Toast.LENGTH_SHORT).show();
                }
            }
        });
        // Create the AlertDialog object and return it
        builder.create().show();
    }
}
 
开发者ID:rushdroid,项目名称:SharedPermission,代码行数:30,代码来源:PermissionHandler.java

示例10: tryAgain

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public void tryAgain(Activity activity, Fragment fragment, boolean isFragment) {
    if (isFragment) {
        if (fragment != null) {
            fragment.requestPermissions(notHasPermission, currentRequestCode);
        }
    } else {
        if (activity != null) {
            ActivityCompat.requestPermissions(activity, notHasPermission, currentRequestCode);
        }
    }

}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:13,代码来源:SinglePermission.java

示例11: checkCameraPermission

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public static boolean checkCameraPermission(Fragment fragment) {
    int cameraPermissionState = ContextCompat.checkSelfPermission(fragment.getContext(), CAMERA);

    boolean cameraPermissionGranted = cameraPermissionState == PackageManager.PERMISSION_GRANTED;

    if (!cameraPermissionGranted) {
        fragment.requestPermissions(PermissionsConstant.PERMISSIONS_CAMERA,
                PermissionsConstant.REQUEST_CAMERA);
    }
    return cameraPermissionGranted;
}
 
开发者ID:malijie,项目名称:PhotoPicker-master,代码行数:12,代码来源:PermissionsUtils.java

示例12: requestReadExternalStoragePermission

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public static void requestReadExternalStoragePermission(@NonNull Fragment fragment, int requestCode){
    if(Utils.hasMarshmallow()){
        fragment.requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, requestCode);
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:6,代码来源:AppPerms.java

示例13: requestForStoragePermission

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public static void requestForStoragePermission(Fragment fragment) {
    fragment.requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
            android.Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_CODE);
}
 
开发者ID:metarhia,项目名称:metacom-android,代码行数:5,代码来源:PermissionUtils.java

示例14: requestPermissions

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public static void requestPermissions(Fragment fragment, String[] permission, int requestCode) {
    if (useRunTimePermissions()) {
        fragment.requestPermissions(permission, requestCode);
    }
}
 
开发者ID:marcoscgdev,项目名称:EasyPermissions,代码行数:6,代码来源:EasyPermissions.java


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