Search in sources :

Example 1 with RxPermissions

use of com.tbruyelle.rxpermissions.RxPermissions in project MVPArms by JessYanCoding.

the class UserActivity method setupActivityComponent.

@Override
protected void setupActivityComponent(AppComponent appComponent) {
    this.mRxPermissions = new RxPermissions(this);
    DaggerUserComponent.builder().appComponent(appComponent).userModule(new UserModule(this)).build().inject(this);
}
Also used : RxPermissions(com.tbruyelle.rxpermissions.RxPermissions) UserModule(me.jessyan.mvparms.demo.di.module.UserModule)

Example 2 with RxPermissions

use of com.tbruyelle.rxpermissions.RxPermissions in project AppUpdate by WVector.

the class MainActivity method getPermission.

public void getPermission() {
    RxPermissions rxPermissions = new RxPermissions(this);
    rxPermissions.request(WRITE_EXTERNAL_STORAGE).subscribe(new Action1<Boolean>() {

        @Override
        public void call(Boolean aBoolean) {
            if (aBoolean) {
                Toast.makeText(MainActivity.this, "已授权", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(MainActivity.this, "未授权", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : RxPermissions(com.tbruyelle.rxpermissions.RxPermissions)

Example 3 with RxPermissions

use of com.tbruyelle.rxpermissions.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 = (SurfaceView) findViewById(R.id.surfaceView);
    RxView.clicks(findViewById(R.id.enableCamera)).compose(rxPermissions.ensureEach(Manifest.permission.CAMERA)).subscribe(new Action1<Permission>() {

        @Override
        public void call(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 Action1<Throwable>() {

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

        @Override
        public void call() {
            Log.i(TAG, "OnComplete");
        }
    });
}
Also used : Action0(rx.functions.Action0) RxPermissions(com.tbruyelle.rxpermissions.RxPermissions) Permission(com.tbruyelle.rxpermissions.Permission) IOException(java.io.IOException)

Aggregations

RxPermissions (com.tbruyelle.rxpermissions.RxPermissions)3 Permission (com.tbruyelle.rxpermissions.Permission)1 IOException (java.io.IOException)1 UserModule (me.jessyan.mvparms.demo.di.module.UserModule)1 Action0 (rx.functions.Action0)1