Java Code Examples for pub.devrel.easypermissions.EasyPermissions#requestPermissions()

The following examples show how to use pub.devrel.easypermissions.EasyPermissions#requestPermissions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From apps-script-mobile-addons with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to initialize credentials and service object (prior to a call
 * to the API); uses the account provided by the calling app. This
 * requires the GET_ACCOUNTS permission to be explicitly granted by the
 * user; this will be requested here if it is not already granted. The
 * AfterPermissionGranted annotation indicates that this function will be
 * rerun automatically whenever the GET_ACCOUNTS permission is granted.
 */
@AfterPermissionGranted(REQUEST_PERMISSION_GET_ACCOUNTS)
private void createCredentialsAndService() {
    if (EasyPermissions.hasPermissions(
            MainActivity.this, Manifest.permission.GET_ACCOUNTS)) {
        mCredential = GoogleAccountCredential.usingOAuth2(
                getApplicationContext(), Arrays.asList(SCOPES))
                .setBackOff(new ExponentialBackOff())
                .setSelectedAccountName(mAccount.name);
        mService = new com.google.api.services.script.Script.Builder(
                mTransport, mJsonFactory, setHttpTimeout(mCredential))
                .setApplicationName(getString(R.string.app_name))
                .build();
        updateButtonEnableStatus();

        // Callback to retry the API call with valid service/credentials
        callAppsScriptTask(mLastFunctionCalled);
    } else {
        // Request the GET_ACCOUNTS permission via a user dialog
        EasyPermissions.requestPermissions(
                MainActivity.this,
                getString(R.string.get_accounts_rationale),
                REQUEST_PERMISSION_GET_ACCOUNTS,
                Manifest.permission.GET_ACCOUNTS);
    }
}
 
Example 2
Source File: MainActivity.java    From blinkreceipt-android with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected (MenuItem item ) {
    switch( item.getItemId() ) {
        case R.id.sdk_version:
            new AlertDialog.Builder( this )
                    .setTitle( R.string.sdk_version_dialog_title )
                    .setMessage( BlinkReceiptSdk.versionName( this ) )
                    .setPositiveButton(android.R.string.ok, (dialog, which) -> dialog.dismiss())
                    .create()
                    .show();

            return true;
        case R.id.camera:
            if ( EasyPermissions.hasPermissions( this, requestPermissions ) ) {
                startCameraScanForResult();
            } else {
                EasyPermissions.requestPermissions(this, getString( R.string.permissions_rationale ),
                        PERMISSIONS_REQUEST_CODE, requestPermissions );
            }

            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 3
Source File: FeedAddActivity.java    From SmallGdufe-Android with GNU General Public License v3.0 6 votes vote down vote up
@AfterPermissionGranted(PRC_PHOTO_PICKER)
private void choicePhotoWrapper() {
    String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
    if (EasyPermissions.hasPermissions(this, perms)) {
        // 拍照后照片的存放目录,改成你自己拍照后要存放照片的目录。如果不传递该参数的话就没有拍照功能
        File takePhotoDir = new File(Environment.getExternalStorageDirectory(), AppConfig.sdSaveDirName);

        Intent photoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
                .cameraFileDir(takePhotoDir) // 拍照后照片的存放目录,改成你自己拍照后要存放照片的目录。如果不传递该参数的话则不开启图库里的拍照功能
                .maxChooseCount(mPhotosSnpl.getMaxItemCount() - mPhotosSnpl.getItemCount()) // 图片选择张数的最大值
                .selectedPhotos(null) // 当前已选中的图片路径集合
                .pauseOnScroll(false) // 滚动列表时是否暂停加载图片
                .build();
        startActivityForResult(photoPickerIntent, RC_CHOOSE_PHOTO);
    } else {
        EasyPermissions.requestPermissions(this, "图片选择需要以下权限:\n\n1.访问设备上的照片\n\n2.拍照", PRC_PHOTO_PICKER, perms);
    }
}
 
Example 4
Source File: UserInfoActivity.java    From iMoney with Apache License 2.0 6 votes vote down vote up
@OnClick({R.id.iv_back, R.id.tv_icon, R.id.logout})
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.iv_back: // 返回按钮退出
            removeCurrentActivity();
            break;
        case R.id.tv_icon:
            if (EasyPermissions.hasPermissions(this, perms)) {
                changeIcon();
            } else {
                EasyPermissions.requestPermissions(this, "应用程序需要这些权限", 520, perms);
            }
            break;
        case R.id.logout: // 退出登录的回调
            logout(view);
            break;
    }
}
 
Example 5
Source File: StartUI.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
@AfterPermissionGranted(NeededPermissions)
private void requestNeededPermissions() {
    String PREF_FIRST_START = "FirstStart";
    SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREF_FIRST_START, Context.MODE_PRIVATE);
    long FirstStartTime = FirstStart.getLong(PREF_FIRST_START, 0);
    if (EasyPermissions.hasPermissions(this, perms)) {
        // Already have permission, start ConversationsActivity
        Log.d(Config.LOGTAG, "All permissions granted, starting " + getString(R.string.app_name) + "(" + FirstStartTime + ")");
        Intent intent = new Intent(this, ConversationsActivity.class);
        intent.putExtra(PREF_FIRST_START, FirstStartTime);
        startActivity(intent);
        overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
        finish();
    } else {
        // set first start to 0 if there are permissions to request
        Log.d(Config.LOGTAG, "Requesting required permissions");
        SharedPreferences.Editor editor = FirstStart.edit();
        editor.putLong(PREF_FIRST_START, 0);
        editor.commit();
        // Do not have permissions, request them now
        EasyPermissions.requestPermissions(this, getString(R.string.request_permissions_message),
                NeededPermissions, perms);
    }
}
 
Example 6
Source File: ImageActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.button_choose_photo)
@AfterPermissionGranted(RC_IMAGE_PERMS)
protected void choosePhoto() {
    if (!EasyPermissions.hasPermissions(this, PERMS)) {
        EasyPermissions.requestPermissions(this, getString(R.string.rational_image_perm),
                                           RC_IMAGE_PERMS, PERMS);
        return;
    }

    Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, RC_CHOOSE_PHOTO);
}
 
Example 7
Source File: UserInfoActivity.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@AfterPermissionGranted(520)
private void methodRequiresTwoPermission() {
    if (EasyPermissions.hasPermissions(this, perms)) {
        // Already have permission, do the thing
        changeIcon();
    } else {
        // Do not have permissions, request them now
        EasyPermissions.requestPermissions(this, "请求相机和相册权限",
                520, perms);
    }
}
 
Example 8
Source File: WebViewActivity.java    From PKUCourses with GNU General Public License v3.0 5 votes vote down vote up
public void startDownload() {

        //check if app has permission to write to the external storage.
        if (EasyPermissions.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            //Get the URL entered
            new DownloadFile().execute();

        } else {
            //If permission is not present request for the same.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                EasyPermissions.requestPermissions(this, "PKU Courses是开源软件,绝不会滥用权限。请授权存储权限以下载文件。", WRITE_REQUEST_CODE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
            }
        }
    }
 
Example 9
Source File: OPMLCreateHelper.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
public void run(){
    String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(activity, perms)) {
        //有权限
       add();
    } else {
        //没有权限 1. 申请权限
        EasyPermissions.requestPermissions(
                new PermissionRequest.Builder(activity, REQUEST_STORAGE_WRITE, perms)
                        .setRationale("必须允许写存储器才能导出OPML文件")
                        .setPositiveButtonText("确定")
                        .setNegativeButtonText("取消")
                        .build());
    }
}
 
Example 10
Source File: ShopLocationActivity.java    From FaceT with Mozilla Public License 2.0 5 votes vote down vote up
@AfterPermissionGranted(RC_LOCATION_PERM)
public void locationTask() {
    String[] perms = {Manifest.permission.ACCESS_FINE_LOCATION};
    if (EasyPermissions.hasPermissions(this, perms)) {
        // Have permissions, do the thing!
    } else {
        // Ask for both permissions
        EasyPermissions.requestPermissions(this, getString(R.string.rationale_location_contacts),
                RC_LOCATION_PERM, perms);
    }
}
 
Example 11
Source File: IndexDelegate.java    From FastWaiMai with MIT License 5 votes vote down vote up
@Override
public void onLazyInitView(@Nullable Bundle savedInstanceState) {
	super.onLazyInitView(savedInstanceState);
	initTouchListener();
	initTabLayout();
	if (EasyPermissions.hasPermissions(Latte.getApplication(), perms)) {
		initLocation();
	}else{
		EasyPermissions.requestPermissions(this, "请打开相关权限", 1, perms);
	}
}
 
Example 12
Source File: SplashActivity.java    From letv with Apache License 2.0 5 votes vote down vote up
@AfterPermissionGranted(100)
private void doApplyPermissions() {
    if (EasyPermissions.hasPermissions(this, EasyPermissions.PERMS)) {
        LogInfo.log("zhuqiao", "doApplyPermissions success");
        init();
        return;
    }
    EasyPermissions.requestPermissions(this, getString(2131100595), 100, EasyPermissions.PERMS);
}
 
Example 13
Source File: SettingsFragmentView.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
@AfterPermissionGranted(IconPackHelper.PICK_ICON) private void pickIcon() {
    if (EasyPermissions.hasPermissions(getContext(), permissions)) {
        IconPackHelper.pickIconPack(this, true);
    } else {
        EasyPermissions.requestPermissions(this, getString(R.string.write_sdcard_explanation),
                IconPackHelper.PICK_ICON, permissions);
    }
}
 
Example 14
Source File: MainActivity.java    From SocialSDKAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    //申请权限
    String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
    if (!EasyPermissions.hasPermissions(this, perms)) {
        EasyPermissions.requestPermissions(this, "need access external storage", REQUEST_LOCATION, perms);
    }
}
 
Example 15
Source File: MainActivity.java    From easypermissions with Apache License 2.0 5 votes vote down vote up
@AfterPermissionGranted(RC_LOCATION_CONTACTS_PERM)
public void locationAndContactsTask() {
    if (hasLocationAndContactsPermissions()) {
        // Have permissions, do the thing!
        Toast.makeText(this, "TODO: Location and Contacts things", Toast.LENGTH_LONG).show();
    } else {
        // Ask for both permissions
        EasyPermissions.requestPermissions(
                this,
                getString(R.string.rationale_location_contacts),
                RC_LOCATION_CONTACTS_PERM,
                LOCATION_AND_CONTACTS);
    }
}
 
Example 16
Source File: MainFragment.java    From easypermissions with Apache License 2.0 5 votes vote down vote up
@AfterPermissionGranted(RC_SMS_PERM)
private void smsTask() {
    if (EasyPermissions.hasPermissions(getContext(), Manifest.permission.READ_SMS)) {
        // Have permission, do the thing!
        Toast.makeText(getActivity(), "TODO: SMS things", Toast.LENGTH_LONG).show();
    } else {
        // Request one permission
        EasyPermissions.requestPermissions(this, getString(R.string.rationale_sms),
                RC_SMS_PERM, Manifest.permission.READ_SMS);
    }
}
 
Example 17
Source File: SocialFragment.java    From SmallGdufe-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 图片预览,兼容6.0动态权限
 */
@AfterPermissionGranted(PRC_PHOTO_PREVIEW)
private void photoPreviewWrapper() {

    if (mCurrentClickNpl == null) {
        return;
    }

    String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(getActivity(), perms)) {
        File downloadDir = new File(Environment.getExternalStorageDirectory(), "SmallGdufeDownload");
        BGAPhotoPreviewActivity.IntentBuilder photoPreviewIntentBuilder = new BGAPhotoPreviewActivity.IntentBuilder(getActivity())
                .saveImgDir(downloadDir); // 保存图片的目录,如果传 null,则没有保存图片功能

        if (mCurrentClickNpl.getItemCount() == 1) {
            // 预览单张图片
            photoPreviewIntentBuilder.previewPhoto(mCurrentClickNpl.getCurrentClickItem());
        } else if (mCurrentClickNpl.getItemCount() > 1) {
            // 预览多张图片
            photoPreviewIntentBuilder.previewPhotos(mCurrentClickNpl.getData())
                    .currentPosition(mCurrentClickNpl.getCurrentClickItemPosition()); // 当前预览图片的索引
        }
        startActivity(photoPreviewIntentBuilder.build());
    } else {
        EasyPermissions.requestPermissions(this, "图片预览需要以下权限:\n\n1.访问设备上的照片", PRC_PHOTO_PREVIEW, perms);
    }
}
 
Example 18
Source File: PickerActivity.java    From MediaPickerPoject with MIT License 5 votes vote down vote up
@AfterPermissionGranted(119)
void getMediaData() {
    if (EasyPermissions.hasPermissions(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
        int type = argsIntent.getIntExtra(PickerConfig.SELECT_MODE, PickerConfig.PICKER_IMAGE_VIDEO);
        if (type == PickerConfig.PICKER_IMAGE_VIDEO) {
            getLoaderManager().initLoader(type, null, new MediaLoader(this, this));
        } else if (type == PickerConfig.PICKER_IMAGE) {
            getLoaderManager().initLoader(type, null, new ImageLoader(this, this));
        } else if (type == PickerConfig.PICKER_VIDEO) {
            getLoaderManager().initLoader(type, null, new VideoLoader(this, this));
        }
    } else {
        EasyPermissions.requestPermissions(this, getString(R.string.READ_EXTERNAL_STORAGE), 119, Manifest.permission.READ_EXTERNAL_STORAGE);
    }
}
 
Example 19
Source File: NewPostActivity.java    From friendlypix-android with Apache License 2.0 5 votes vote down vote up
@AfterPermissionGranted(RC_CAMERA_PERMISSIONS)
private void showImagePicker() {
    // Check for camera permissions
    if (!EasyPermissions.hasPermissions(this, cameraPerms)) {
        EasyPermissions.requestPermissions(this,
                "This sample will upload a picture from your Camera",
                RC_CAMERA_PERMISSIONS, cameraPerms);
        return;
    }

    // Choose file storage location
    File file = new File(getExternalCacheDir(), UUID.randomUUID().toString());
    mFileUri = Uri.fromFile(file);

    // Camera
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam){
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);
        cameraIntents.add(intent);
    }

    // Image Picker
    Intent pickerIntent = new Intent(Intent.ACTION_PICK,
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    Intent chooserIntent = Intent.createChooser(pickerIntent,
            getString(R.string.picture_chooser_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new
            Parcelable[cameraIntents.size()]));
    startActivityForResult(chooserIntent, TC_PICK_IMAGE);
}
 
Example 20
Source File: MainActivity.java    From CombineBitmap with Apache License 2.0 3 votes vote down vote up
@AfterPermissionGranted(1000)
private void requestStoragePermission() {
    String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(this, perms)) {
        loadDingBitmap(imageView1, 2);

        loadDingBitmap(imageView2, 3);

        loadDingBitmap(imageView3, 4);

        loadWechatBitmap(imageView4, 2);

        loadWechatBitmap(imageView5, 3);

        loadWechatBitmap(imageView6, 4);

        loadWechatBitmap(imageView7, 5);

        loadWechatBitmap(imageView8, 6);

        loadWechatBitmap(imageView9, 7);

        loadWechatBitmap(imageView10, 8);

        loadWechatBitmap(imageView11, 9);

    } else {
        EasyPermissions.requestPermissions(this, "need storage permission", 1000, perms);
    }
}