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