當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。