Search in sources :

Example 1 with AfterPermissionGranted

use of pub.devrel.easypermissions.AfterPermissionGranted in project Pix-Art-Messenger by kriztan.

the class StartUI method requestNeededPermissions.

@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, ConversationActivity.class);
        intent.putExtra(PREF_FIRST_START, FirstStartTime);
        startActivity(intent);
        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);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) AfterPermissionGranted(pub.devrel.easypermissions.AfterPermissionGranted)

Example 2 with AfterPermissionGranted

use of pub.devrel.easypermissions.AfterPermissionGranted in project JustAndroid by chinaltz.

the class OtherUtilsFragment method didQrStartCapture.

@AfterPermissionGranted(REQUEST_QRCamera_PERM)
public void didQrStartCapture() {
    if (EasyPermissions.hasPermissions(mContext, Manifest.permission.CAMERA)) {
        Intent intent = new Intent();
        intent.setClass(mContext, QRCaptureActivity.class);
        startActivity(intent);
    } else {
        // Ask for one permission
        EasyPermissions.requestPermissions(this, "需要使用相机信息权限", REQUEST_QRCamera_PERM, Manifest.permission.CAMERA);
    }
}
Also used : Intent(android.content.Intent) AfterPermissionGranted(pub.devrel.easypermissions.AfterPermissionGranted)

Example 3 with AfterPermissionGranted

use of pub.devrel.easypermissions.AfterPermissionGranted in project CustomViews by AndroidStudy233.

the class MomentAddActivity method choicePhotoWrapper.

@AfterPermissionGranted(REQUEST_CODE_PERMISSION_PHOTO_PICKER)
private void choicePhotoWrapper() {
    String[] perms = { Manifest.permission.WRITE_EXTERNAL_STORAGE };
    if (EasyPermissions.hasPermissions(this, perms)) {
        // 拍照后照片的存放目录,改成你自己拍照后要存放照片的目录。如果不传递该参数的话就没有拍照功能
        File takePhotoDir = new File(Environment.getExternalStorageDirectory(), "BGAPhotoPickerTakePhoto");
        startActivityForResult(BGAPhotoPickerActivity.newIntent(this, mTakePhotoCb.isChecked() ? takePhotoDir : null, mSingleChoiceCb.isChecked() ? 1 : mPhotosSnpl.getMaxItemCount(), mPhotosSnpl.getData(), true), REQUEST_CODE_CHOOSE_PHOTO);
    } else {
        EasyPermissions.requestPermissions(this, "图片选择需要以下权限:\n\n1.访问设备上的照片", REQUEST_CODE_PERMISSION_PHOTO_PICKER, perms);
    }
}
Also used : File(java.io.File) AfterPermissionGranted(pub.devrel.easypermissions.AfterPermissionGranted)

Example 4 with AfterPermissionGranted

use of pub.devrel.easypermissions.AfterPermissionGranted in project CustomViews by AndroidStudy233.

the class MomentListActivity method photoPreviewWrapper.

/**
 * 图片预览,兼容6.0动态权限
 */
@AfterPermissionGranted(REQUEST_CODE_PERMISSION_PHOTO_PREVIEW)
private void photoPreviewWrapper() {
    if (mCurrentClickNpl == null) {
        return;
    }
    // 保存图片的目录,改成你自己要保存图片的目录。如果不传递该参数的话就不会显示右上角的保存按钮
    File downloadDir = new File(Environment.getExternalStorageDirectory(), "BGAPhotoPickerDownload");
    String[] perms = { Manifest.permission.WRITE_EXTERNAL_STORAGE };
    if (EasyPermissions.hasPermissions(this, perms)) {
        if (mCurrentClickNpl.getItemCount() == 1) {
            // 预览单张图片
            startActivity(BGAPhotoPreviewActivity.newIntent(this, mDownLoadableCb.isChecked() ? downloadDir : null, mCurrentClickNpl.getCurrentClickItem()));
        } else if (mCurrentClickNpl.getItemCount() > 1) {
            // 预览多张图片
            startActivity(BGAPhotoPreviewActivity.newIntent(this, mDownLoadableCb.isChecked() ? downloadDir : null, mCurrentClickNpl.getData(), mCurrentClickNpl.getCurrentClickItemPosition()));
        }
    } else {
        EasyPermissions.requestPermissions(this, "图片预览需要以下权限:\n\n1.访问设备上的照片", REQUEST_CODE_PERMISSION_PHOTO_PREVIEW, perms);
    }
}
Also used : File(java.io.File) AfterPermissionGranted(pub.devrel.easypermissions.AfterPermissionGranted)

Example 5 with AfterPermissionGranted

use of pub.devrel.easypermissions.AfterPermissionGranted in project JustAndroid by chinaltz.

the class MapActivity method didLocation.

@AfterPermissionGranted(REQUEST_LOCATION_PERM)
public void didLocation() {
    if (EasyPermissions.hasPermissions(this, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        locationProvider = new LocationProvider(this);
        // 获取locationservice实例,建议应用中只初始化1个location实例,然后使用,可以参考其他示例的activity,都是通过此种方式获取locationservice实例的
        locationProvider.registerListener(locationListener);
        // 注册监听
        locationProvider.setLocationOption(locationProvider.getDefaultOption());
        locationProvider.start();
    } else {
        // Ask for one permission
        EasyPermissions.requestPermissions(this, "需要使用位置信息权限", REQUEST_LOCATION_PERM, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
}
Also used : LocationProvider(com.litingzhe.justandroid.ui.mapView.AMapUtils.LocationProvider) AfterPermissionGranted(pub.devrel.easypermissions.AfterPermissionGranted)

Aggregations

AfterPermissionGranted (pub.devrel.easypermissions.AfterPermissionGranted)8 Intent (android.content.Intent)4 File (java.io.File)3 SharedPreferences (android.content.SharedPreferences)1 LocationProvider (com.litingzhe.justandroid.ui.mapView.AMapUtils.LocationProvider)1