本文整理汇总了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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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();
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}