pub.devrel.easypermissions.EasyPermissions Java Examples
The following examples show how to use
pub.devrel.easypermissions.EasyPermissions.
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: WiFiActivity.java From android_connectionbuddy with Apache License 2.0 | 6 votes |
@AfterPermissionGranted(RC_LOCATION) private void connectToWifi() { String[] perms = {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}; if (EasyPermissions.hasPermissions(this, perms)) { try { ConnectionBuddy.getInstance() .connectToWifiConfiguration(this, etSsid.getText().toString(), etPassword.getText().toString(), true, WiFiActivity.this); } catch (SecurityException e) { e.printStackTrace(); } } else { // Do not have permissions, request them now EasyPermissions.requestPermissions(this, getString(R.string.change_wifi_state_rationale), RC_LOCATION, perms); } }
Example #2
Source File: OPMLReadHelper.java From Focus with GNU General Public License v3.0 | 6 votes |
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 #3
Source File: MainActivity.java From ClassicBluetooth with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); mContext = this; mList.setAdapter(new ArrayAdapter<>(this, R.layout.item_list, R.id.tv_items, mTitle)); initListener(); String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}; if (!EasyPermissions.hasPermissions(this, perms)) { EasyPermissions.requestPermissions(this, "App正常运行需要存储权限、媒体权限", 1, perms); } }
Example #4
Source File: UserInfoActivity.java From iMoney with Apache License 2.0 | 6 votes |
@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: MainActivity.java From OneText_For_Android with GNU Lesser General Public License v3.0 | 6 votes |
public void requestPermissions(final String[] permissions) { //申请权限 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { request_permissions_layout.setVisibility(View.GONE); } else { if (EasyPermissions.hasPermissions(this, permissions)) { //已经打开权限 //Toast.makeText(this, "已经申请相关权限", Toast.LENGTH_SHORT).show(); request_permissions_layout.setVisibility(View.GONE); } else { //没有打开相关权限、申请权限 request_permissions_layout.setVisibility(View.VISIBLE); request_permissions_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EasyPermissions.requestPermissions(MainActivity.this, getString(R.string.request_permissions_storage_detail_text).replace("%s", Environment.getExternalStorageDirectory() + "/Pictures/OneText/"), 1, permissions); } }); } } }
Example #6
Source File: HomeFragment.java From star-zone-android with Apache License 2.0 | 6 votes |
/** * 请求读取sd卡的权限. 保存支付宝照片到相册的时候 */ private void requestPermission() { if (Build.VERSION.SDK_INT >= 23) { //读取sd卡的权限 String[] mPermissionList = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; if (EasyPermissions.hasPermissions(getActivity(), mPermissionList)) { //已经同意过 saveImage(); } else { //未同意过,或者说是拒绝了,再次申请权限 EasyPermissions.requestPermissions( this, //上下文 "保存图片需要读取sd卡的权限", //提示文言 REQUEST_CODE_SAVE_IMG, //请求码 mPermissionList //权限列表 ); } } else { saveImage(); } }
Example #7
Source File: AboutActivity.java From star-zone-android with Apache License 2.0 | 6 votes |
/** * 请求读取sd卡的权限 */ private void requestPermission() { if (Build.VERSION.SDK_INT >= 23) { //读取sd卡的权限 String[] mPermissionList = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; if (EasyPermissions.hasPermissions(this, mPermissionList)) { //已经同意过 saveImage(); } else { //未同意过,或者说是拒绝了,再次申请权限 EasyPermissions.requestPermissions( this, //上下文 "保存图片需要读取sd卡的权限", //提示文言 REQUEST_CODE_SAVE_IMG, //请求码 mPermissionList //权限列表 ); } } else { saveImage(); } }
Example #8
Source File: AuthActivity.java From mvvm-starter with MIT License | 6 votes |
@Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_auth); //request location permission early if (!EasyPermissions.hasPermissions(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION)) { EasyPermissions .requestPermissions(AuthActivity.this, S.location_permission_message, I.LOCATION_REQUEST_CODE, Manifest.permission.ACCESS_FINE_LOCATION); } // init first fragment ft = fm.beginTransaction(); ft.add(R.id.fl_fragment_container, loginFragment); ft.commit(); }
Example #9
Source File: BaseActivity.java From VideoAndroid with Apache License 2.0 | 6 votes |
@Override public void onPermissionsDenied(int requestCode, List<String> perms) { if(mPermissonCallbacks == null || !mPermissonCallbacks.containsKey(requestCode)) { return; } if(mPermissions == null || !mPermissions.containsKey(requestCode)) { return; } //granted permission List<String> grantedPerms = new ArrayList<>(); for(String perm : mPermissions.get(requestCode)) { if(!perms.contains(perm)) { grantedPerms.add(perm); } } //check has permission denied permanently if(EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { mPermissonCallbacks.get(requestCode).noPermission(perms, grantedPerms, true); } else { mPermissonCallbacks.get(requestCode).noPermission(perms, grantedPerms, false); } }
Example #10
Source File: ImageActivity.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_CHOOSE_PHOTO) { if (resultCode == RESULT_OK) { Uri selectedImage = data.getData(); uploadPhoto(selectedImage); } else { Toast.makeText(this, "No image chosen", Toast.LENGTH_SHORT).show(); } } else if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE && EasyPermissions.hasPermissions(this, PERMS)) { choosePhoto(); } }
Example #11
Source File: GuideActivity.java From YCAudioPlayer with Apache License 2.0 | 6 votes |
@AfterPermissionGranted(RC_LOCATION_CONTACTS_PERM) public void locationPermissionsTask() { //检查是否获取该权限 if (hasPermissions()) { startCheckService(); //具备权限 直接进行操作 startLoading(); //startCheckService(); } else { //权限拒绝 申请权限 //第二个参数是被拒绝后再次申请该权限的解释 //第三个参数是请求码 //第四个参数是要申请的权限 EasyPermissions.requestPermissions(this, getString(R.string.easy_permissions), RC_LOCATION_CONTACTS_PERM, LOCATION_AND_CONTACTS); } }
Example #12
Source File: MainActivity.java From blinkreceipt-android with MIT License | 6 votes |
@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 #13
Source File: GuideActivity.java From YCAudioPlayer with Apache License 2.0 | 6 votes |
/** * 某些权限已被拒绝 */ @Override public void onPermissionsDenied(int requestCode, List<String> perms) { //某些权限已被拒绝 Log.d("权限", "onPermissionsDenied:" + requestCode + ":" + perms.size()); // (Optional) Check whether the user denied any permissions and checked "NEVER ASK AGAIN." // This will display a dialog directing them to enable the permission in app settings. if (EasyPermissions.somePermissionPermanentlyDenied(GuideActivity.this, perms)) { AppSettingsDialog.Builder builder = new AppSettingsDialog.Builder(GuideActivity.this); builder.setTitle("允许权限") .setRationale("没有该权限,此应用程序部分功能可能无法正常工作。打开应用设置界面以修改应用权限") .setPositiveButton("去设置") .setNegativeButton("取消") .setRequestCode(RC_LOCATION_CONTACTS_PERM) .build() .show(); }else { ToastUtils.showShort("没有存储空间权限,无法扫描本地歌曲!"); finish(); } }
Example #14
Source File: OPMLReadHelper_backup.java From Focus with GNU General Public License v3.0 | 6 votes |
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 #15
Source File: MainActivity.java From AndroidSamples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); ButterKnife.bind(this); list.setAdapter(new ArrayAdapter<String>(this, R.layout.item_list, R.id.tv_items, mTitle)); // 判断权限 String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}; if (EasyPermissions.hasPermissions(this, perms)) { initListener(); } else { // 如果用户拒绝权限,第二次打开才会显示提示文字 EasyPermissions.requestPermissions(this, "维持App正常运行需要存储权限", RESULT_CODE_1, perms); } }
Example #16
Source File: ServerDetailsActivity.java From droidovpn with GNU General Public License v3.0 | 5 votes |
@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 #17
Source File: SplashActivity.java From ViewCapture with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (EasyPermissions.hasPermissions(this, par)) { goMain(); } }
Example #18
Source File: WebViewActivity.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
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 #19
Source File: MainActivity.java From AndroidApp with Mozilla Public License 2.0 | 5 votes |
/** * Request runtime permissions method */ private void requestWriteExternalStoragePermission() { String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE}; if (EasyPermissions.hasPermissions(this, permissions)) { //Up next .... request Location requestLocationPermission(); } else { // Do not have permissions, request permissions EasyPermissions.requestPermissions(MainActivity.this, getString(R.string.write_storage_request), WRITE_EXTERNAL_STORAGE_PERMISSION, permissions); } }
Example #20
Source File: SettingsFragmentView.java From FastAccess with GNU General Public License v3.0 | 5 votes |
@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 #21
Source File: CameraActivity.java From AndroidSamples with Apache License 2.0 | 5 votes |
@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 #22
Source File: FileViewDemoMainActivity.java From AndroidDocumentViewer with MIT License | 5 votes |
@AfterPermissionGranted(RC_WRITE_STOREGE) private void methodRequiresTwoPermission() { String[] perms = {Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION}; if (EasyPermissions.hasPermissions(this, perms)) { // Already have permission, do the thing // ... } else { // Do not have permissions, request them now EasyPermissions.requestPermissions(this, "请求权限", RC_WRITE_STOREGE, perms); } }
Example #23
Source File: ConfigActivity.java From QuickerAndroid with GNU General Public License v3.0 | 5 votes |
@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 #24
Source File: MainActivity.java From AndroidApp with Mozilla Public License 2.0 | 5 votes |
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 #25
Source File: ShopLocationActivity.java From FaceT with Mozilla Public License 2.0 | 5 votes |
@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 #26
Source File: QrcodeScanActivity.java From QuickerAndroid with GNU General Public License v3.0 | 5 votes |
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); // Forward results to EasyPermissions EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); }
Example #27
Source File: MainActivity.java From AndroidApp with Mozilla Public License 2.0 | 5 votes |
@Override public void onPermissionsDenied(int requestCode, List<String> perms) { if (requestCode == WRITE_EXTERNAL_STORAGE_PERMISSION) { new AppToast(this).longToast(R.string.write_storage_request_toast); //double check that write access is granted, this permission is needed requestWriteExternalStoragePermission(); // (Optional) Check whether the user denied any permissions and checked "NEVER ASK AGAIN." // This will display a dialog directing them to enable the permission in app settings. if (!EasyPermissions.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { new AppSettingsDialog.Builder(this).build().show(); } } else if (requestCode == LOCATION_PERMISSION) { new AppToast(this).longToast(R.string.location_request_toast); //double check that write access is granted, this permission is needed requestLocationPermission(); String[] permissions = {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}; // (Optional) Check whether the user denied any permissions and checked "NEVER ASK AGAIN." // This will display a dialog directing them to enable the permission in app settings. if (!EasyPermissions.hasPermissions(this, permissions)) if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { new AppSettingsDialog.Builder(this).build().show(); } } }
Example #28
Source File: MainActivity.java From Android-AudioRecorder-App with Apache License 2.0 | 5 votes |
@TargetApi(23) private void getPermissions() { String[] permissions = new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}; if (!EasyPermissions.hasPermissions(MainActivity.this, permissions)) { EasyPermissions.requestPermissions(this, getString(R.string.permissions_required), PERMISSION_REQ, permissions); } }
Example #29
Source File: QrcodeScanActivity.java From QuickerAndroid with GNU General Public License v3.0 | 5 votes |
@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); }else { startScan(); } }
Example #30
Source File: BaseActivity.java From MultiType-FilePicker with Apache License 2.0 | 5 votes |
@Override public void onPermissionsDenied(int requestCode, List<String> perms) { Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + perms.size()); // If Permission permanently denied, ask user again if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { new AppSettingsDialog.Builder(this).build().show(); } else { finish(); } }