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);
}
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();
}
}
});
}
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");
}
});
}
Aggregations