Search in sources :

Example 21 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project RxJavaInAction by fengzhizi715.

the class MainActivity method initViews.

@SuppressLint("MissingPermission")
private void initViews() {
    final RxPermissions rxPermissions = new RxPermissions(this);
    RxView.clicks(text1).subscribe(new Consumer<Object>() {

        @Override
        public void accept(@NonNull Object o) throws Exception {
            rxPermissions.request(Manifest.permission.CALL_PHONE).subscribe(new Consumer<Boolean>() {

                @Override
                public void accept(Boolean granted) throws Exception {
                    if (granted) {
                        Intent intent = new Intent(Intent.ACTION_CALL);
                        intent.setData(Uri.parse("tel:" + "10000"));
                        startActivity(intent);
                    } else {
                        L.i("授权失败");
                    }
                }
            });
        }
    });
    RxView.clicks(text2).compose(rxPermissions.ensure(Manifest.permission.CALL_PHONE)).subscribe(new Consumer<Boolean>() {

        @Override
        public void accept(@NonNull Boolean granted) throws Exception {
            if (granted) {
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + "10000"));
                startActivity(intent);
            } else {
                L.i("授权失败");
            }
        }
    });
    RxView.clicks(text3).compose(rxPermissions.ensure(Manifest.permission.CAMERA, Manifest.permission.READ_CONTACTS)).subscribe(new Consumer<Boolean>() {

        @Override
        public void accept(Boolean granted) throws Exception {
            if (granted) {
                Toast.makeText(MainActivity.this, "打开相机成功", Toast.LENGTH_SHORT).show();
            } else {
                L.i("授权失败");
                Toast.makeText(MainActivity.this, "打开相机失败", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) Consumer(io.reactivex.functions.Consumer) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Example 22 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project RxPermissions by tbruyelle.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RxPermissions rxPermissions = new RxPermissions(this);
    rxPermissions.setLogging(true);
    setContentView(R.layout.act_main);
    surfaceView = findViewById(R.id.surfaceView);
    disposable = RxView.clicks(findViewById(R.id.enableCamera)).compose(rxPermissions.ensureEach(permission.CAMERA)).subscribe(new Consumer<Permission>() {

        @Override
        public void accept(Permission permission) {
            Log.i(TAG, "Permission result " + permission);
            if (permission.granted) {
                releaseCamera();
                camera = Camera.open(0);
                try {
                    camera.setPreviewDisplay(surfaceView.getHolder());
                    camera.startPreview();
                } catch (IOException e) {
                    Log.e(TAG, "Error while trying to display the camera preview", e);
                }
            } else if (permission.shouldShowRequestPermissionRationale) {
                // Denied permission without ask never again
                Toast.makeText(MainActivity.this, "Denied permission without ask never again", Toast.LENGTH_SHORT).show();
            } else {
                // Denied permission with ask never again
                // Need to go to the settings
                Toast.makeText(MainActivity.this, "Permission denied, can't enable the camera", Toast.LENGTH_SHORT).show();
            }
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable t) {
            Log.e(TAG, "onError", t);
        }
    }, new Action() {

        @Override
        public void run() {
            Log.i(TAG, "OnComplete");
        }
    });
}
Also used : Action(io.reactivex.rxjava3.functions.Action) RxPermissions(com.tbruyelle.rxpermissions3.RxPermissions) Consumer(io.reactivex.rxjava3.functions.Consumer) Permission(com.tbruyelle.rxpermissions3.Permission) IOException(java.io.IOException)

Example 23 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project DevRing by LJYcoder.

the class PermissionManager method requestEach.

// 请求单个权限建议用这个
public void requestEach(FragmentActivity activity, final PermissionListener listener, String... permissions) {
    if (activity != null) {
        RxPermissions rxPermissions = new RxPermissions(activity);
        rxPermissions.requestEach(permissions).subscribe(new Consumer<Permission>() {

            @Override
            public void accept(Permission permission) throws Exception {
                if (permission.granted) {
                    // `permission.name` is granted !
                    if (listener != null) {
                        listener.onGranted(permission.name);
                    }
                } else if (permission.shouldShowRequestPermissionRationale) {
                    // Denied permission without ask never again
                    if (listener != null) {
                        listener.onDenied(permission.name);
                    }
                } else {
                    // Need to go to the settings
                    if (listener != null) {
                        listener.onDeniedWithNeverAsk(permission.name);
                    }
                }
            }
        });
    }
}
Also used : RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) Permission(com.tbruyelle.rxpermissions2.Permission)

Example 24 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project GwellDemo by dxsdyhm.

the class PanoramaActivity method checkCamerPermission.

private void checkCamerPermission() {
    RxPermissions rxPermissions = new RxPermissions(this);
    rxPermissions.request(Manifest.permission.CAMERA).subscribe(granted -> {
        if (granted) {
            // 在android 6.0之前会默认返回true
            // 已经获取权限
            Log.e("PanoramaActivity", "已授予CAMERA权限");
        } else {
            // 未获取权限
            ToastUtils.ShowError(PanoramaActivity.this, "您没有授权CAMERA权限,请在设置中打开授权", Toast.LENGTH_SHORT, true);
        }
    });
}
Also used : RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions)

Example 25 with RxPermissions

use of com.tbruyelle.rxpermissions3.RxPermissions in project GwellDemo by dxsdyhm.

the class PanoramaActivity method checkSDPermision.

private void checkSDPermision() {
    RxPermissions rxPermissions = new RxPermissions(this);
    boolean result = false;
    rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe(granted -> {
        if (granted) {
            // 在android 6.0之前会默认返回true
            // 已经获取权限
            capture(0);
            Log.e("PanoramaActivity", "已授予STORAGE权限");
        } else {
            // 未获取权限
            ToastUtils.ShowError(PanoramaActivity.this, "您没有授权STORAGE权限,请在设置中打开授权", Toast.LENGTH_SHORT, true);
        }
    });
}
Also used : RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions)

Aggregations

RxPermissions (com.tbruyelle.rxpermissions2.RxPermissions)31 Intent (android.content.Intent)8 SuppressLint (android.annotation.SuppressLint)6 Permission (com.tbruyelle.rxpermissions2.Permission)4 View (android.view.View)3 GifSizeFilter (com.connxun.ltcx.utils.GifSizeFilter)3 RxPermissions (com.tbruyelle.rxpermissions3.RxPermissions)3 Manifest (android.Manifest)2 Uri (android.net.Uri)2 Button (android.widget.Button)2 OnClick (butterknife.OnClick)2 GlideEngine (com.zhihu.matisse.engine.impl.GlideEngine)2 CaptureStrategy (com.zhihu.matisse.internal.entity.CaptureStrategy)2 Consumer (io.reactivex.functions.Consumer)2 IOException (java.io.IOException)2 Activity (android.app.Activity)1 Context (android.content.Context)1 ActivityInfo (android.content.pm.ActivityInfo)1 Cursor (android.database.Cursor)1 Bundle (android.os.Bundle)1