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

The following examples show how to use pub.devrel.easypermissions.EasyPermissions#hasPermissions() . 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: BaseActivity.java    From VideoAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * request permission
 * @param rationale if denied first, next request rationale
 * @param requestCode requestCode
 * @param perms permissions
 * @param callback callback
 */
protected void performCodeWithPermission(@NonNull String rationale,
                                         final int requestCode, @NonNull String[] perms, @NonNull PermissionCallback callback) {
    if (EasyPermissions.hasPermissions(this, perms)) {
        callback.hasPermission(Arrays.asList(perms));
    } else {
        if(mPermissonCallbacks == null) {
            mPermissonCallbacks = new HashMap<>();
        }
        mPermissonCallbacks.put(requestCode, callback);

        if(mPermissions == null) {
            mPermissions = new HashMap<>();
        }
        mPermissions.put(requestCode, perms);

        EasyPermissions.requestPermissions(this, rationale, requestCode, perms);
    }
}
 
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: OPMLReadHelper.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
public void run(){
    String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(activity, perms)) {
        //有权限
        new FileChooserDialog.Builder(activity)
                .initialPath(GlobalConfig.appDirPath)  //初始显示了目录
                .extensionsFilter(".opml",".xml") //选择的文件类型
                .tag("optional-identifier")
                .goUpLabel("上一级")
                .show((FeedManageActivity)activity);


    } else {
        //没有权限 1. 申请权限
        EasyPermissions.requestPermissions(
                new PermissionRequest.Builder(activity, RQUEST_STORAGE_READ, perms)
                        .setRationale("必须读存储器才能解析OPML文件")
                        .setPositiveButtonText("确定")
                        .setNegativeButtonText("取消")
                        .build());
    }


}
 
Example 4
Source File: OPMLReadHelper_backup.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
public void run(){
    String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(activity, perms)) {
        //有权限
        new FileChooserDialog.Builder(activity)
                .initialPath(GlobalConfig.appDirPath)  //初始显示了目录
                .extensionsFilter(".opml",".xml") //选择的文件类型
                .tag("optional-identifier")
                .goUpLabel("上一级")
                .show((FeedManageActivity)activity);


    } else {
        //没有权限 1. 申请权限
        EasyPermissions.requestPermissions(
                new PermissionRequest.Builder(activity, RQUEST_STORAGE_READ, perms)
                        .setRationale("必须读存储器才能解析OPML文件")
                        .setPositiveButtonText("确定")
                        .setNegativeButtonText("取消")
                        .build());
    }


}
 
Example 5
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 6
Source File: MainActivity.java    From RTCStartupDemo with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final EditText serverEditText = findViewById(R.id.ServerEditText);
    final EditText roomEditText = findViewById(R.id.RoomEditText);
    findViewById(R.id.JoinRoomBtn).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String addr = serverEditText.getText().toString();
            String roomName = roomEditText.getText().toString();
            if (!"".equals(roomName)) {
                Intent intent = new Intent(MainActivity.this, CallActivity.class);
                intent.putExtra("ServerAddr", addr);
                intent.putExtra("RoomName", roomName);
                startActivity(intent);
            }
        }
    });

    String[] perms = {Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO};
    if (!EasyPermissions.hasPermissions(this, perms)) {
        EasyPermissions.requestPermissions(this, "Need permissions for camera & microphone", 0, perms);
    }
}
 
Example 7
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 8
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 9
Source File: SystemGalleryActivity.java    From SmallGdufe-Android with GNU General Public License v3.0 5 votes vote down vote up
@AfterPermissionGranted(REQUEST_CODE_PERMISSION_CHOOSE_PHOTO)
public void choosePhoto() {
    String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(this, perms)) {
        startActivityForResult(mPhotoHelper.getChooseSystemGalleryIntent(), REQUEST_CODE_CHOOSE_PHOTO);
    } else {
        EasyPermissions.requestPermissions(this, "请开起存储空间权限,以正常使用 Demo", REQUEST_CODE_PERMISSION_CHOOSE_PHOTO, perms);
    }
}
 
Example 10
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 11
Source File: CameraActivity.java    From AndroidSamples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);
    ButterKnife.bind(this);

    // 判断权限
    if (EasyPermissions.hasPermissions(this, mPerms)) {
    } else {
        // 如果用户拒绝权限,第二次打开才会显示提示文字
        EasyPermissions.requestPermissions(this, "使用拍照功能需要拍照权限!", PERMISSIONS_CODE_1, mPerms);
    }
}
 
Example 12
Source File: MainActivity.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
private void requestLocationPermission() {
    String[] permissions = {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION};
    if (EasyPermissions.hasPermissions(this, permissions)) {
        //do nothing
        checkLocationServicesStatus();
    } else {
        // Do not have permissions, request permissions
        EasyPermissions.requestPermissions(MainActivity.this,
                getString(R.string.location_request),
                LOCATION_PERMISSION,
                permissions);
    }
}
 
Example 13
Source File: SplashActivity.java    From ViewCapture with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (EasyPermissions.hasPermissions(this, par)) {
        goMain();
    }
}
 
Example 14
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 15
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 16
Source File: ConfigActivity.java    From QuickerAndroid with GNU General Public License v3.0 5 votes vote down vote up
@AfterPermissionGranted(REQUEST_CODE_QRCODE_PERMISSIONS)
private void requestCodeQRCodePermissions() {
    String[] perms = {Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE};
    if (!EasyPermissions.hasPermissions(this, perms)) {
        EasyPermissions.requestPermissions(this, "扫描二维码需要打开相机和散光灯的权限", REQUEST_CODE_QRCODE_PERMISSIONS, perms);
    }
}
 
Example 17
Source File: SettingsFragmentView.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
@AfterPermissionGranted(ActivityHelper.SELECT_PHOTO_REQUEST) private void pickImage() {
    if (EasyPermissions.hasPermissions(getContext(), permissions)) {
        ActivityHelper.startGalleryIntent(this);
    } else {
        EasyPermissions.requestPermissions(this, getString(R.string.write_sdcard_explanation),
                ActivityHelper.SELECT_PHOTO_REQUEST, permissions);
    }
}
 
Example 18
Source File: ServerDetailsActivity.java    From droidovpn with GNU General Public License v3.0 5 votes vote down vote up
@AfterPermissionGranted(RC_WRITE_EXTERNAL_STORAGE_PERM)
private void importToOpenVpn() {
    if (EasyPermissions.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        OvpnUtils.importToOpenVpn(ServerDetailsActivity.this, server);
    } else {
        EasyPermissions.requestPermissions(this, getString(R.string.rationale_write_external),
                RC_WRITE_EXTERNAL_STORAGE_PERM, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
}
 
Example 19
Source File: MainActivity.java    From easypermissions with Apache License 2.0 4 votes vote down vote up
private boolean hasLocationAndContactsPermissions() {
    return EasyPermissions.hasPermissions(this, LOCATION_AND_CONTACTS);
}
 
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);
    }
}