本文整理匯總了Java中com.tbruyelle.rxpermissions2.RxPermissions類的典型用法代碼示例。如果您正苦於以下問題:Java RxPermissions類的具體用法?Java RxPermissions怎麽用?Java RxPermissions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RxPermissions類屬於com.tbruyelle.rxpermissions2包,在下文中一共展示了RxPermissions類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendSms
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
/**
* 請求發送短信權限
*/
public static void sendSms(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
//先確保是否已經申請過權限
boolean isPermissionsGranted =
rxPermissions
.isGranted(Manifest.permission.SEND_SMS);
if (isPermissionsGranted) {//已經申請過,直接執行操作
requestPermission.onRequestPermissionSuccess();
} else {//沒有申請過,則申請
rxPermissions
.request(Manifest.permission.SEND_SMS)
.subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
@Override
public void onNext(Boolean granted) {
if (granted) {
Timber.tag(TAG).d("request SEND_SMS success");
requestPermission.onRequestPermissionSuccess();
} else {
view.showMessage("request permissons failure");
}
}
});
}
}
示例2: start
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
private void start() {
RxPermissions.getInstance(mContext)
.request(WRITE_EXTERNAL_STORAGE)
.doOnNext(new Consumer<Boolean>() {
@Override
public void accept(Boolean granted) throws Exception {
if (!granted) {
throw new RuntimeException("no permission");
}
}
})
.compose(mRxDownload.<Boolean>transformService(data.record.getUrl()))
.subscribe(new Consumer<Object>() {
@Override
public void accept(Object o) throws Exception {
Toast.makeText(mContext, "下載開始", Toast.LENGTH_SHORT).show();
}
});
}
示例3: start
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
private void start() {
RxPermissions.getInstance(mContext)
.request(WRITE_EXTERNAL_STORAGE)
.doOnNext(new Consumer<Boolean>() {
@Override
public void accept(Boolean granted) throws Exception {
if (!granted) {
throw new RuntimeException("no permission");
}
}
})
.compose(mRxDownload.<Boolean>transformService(downloadBean))
.subscribe(new Consumer<Object>() {
@Override
public void accept(Object o) throws Exception {
Toast.makeText(mContext, "下載開始", Toast.LENGTH_SHORT).show();
}
});
}
示例4: start
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
private void start() {
RxPermissions.getInstance(this)
.request(WRITE_EXTERNAL_STORAGE)
.doOnNext(new Consumer<Boolean>() {
@Override
public void accept(Boolean granted) throws Exception {
if (!granted) {
throw new RuntimeException("no permission");
}
}
})
.compose(mRxDownload.<Boolean>transformService(url))
.subscribe(new Consumer<Object>() {
@Override
public void accept(Object o) throws Exception {
Toast.makeText(ServiceDownloadActivity.this, "下載開始", LENGTH_SHORT).show();
}
});
}
示例5: getPermission
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
private void getPermission() {
if(Build.VERSION.SDK_INT < 23){
FloatWindowManager.getInstance().askPermission(this);
}else {
new RxPermissions(this)
.request(Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.SYSTEM_ALERT_WINDOW)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
if(aBoolean){
}
}
});
}
}
示例6: launchRecorder
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
public static void launchRecorder(final RequestPermission requestPermission, final PickerContract.IPickerView view) {
RxPermissions rxPermissions = new RxPermissions((Activity) view);
boolean isPermissionsGranted =
rxPermissions
.isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE) &&
rxPermissions
.isGranted(Manifest.permission.RECORD_AUDIO);
if (isPermissionsGranted) {
requestPermission.onRequestPermissionSuccess();
} else {
rxPermissions
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE
, Manifest.permission.RECORD_AUDIO)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(@NonNull Boolean aBoolean) throws Exception {
if (aBoolean) {
requestPermission.onRequestPermissionSuccess();
} else {
view.showMessage(((Activity) view).getResources().getString(R.string.request_permission_fail));
}
}
});
}
}
示例7: externalStorage
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
public static void externalStorage(final RequestPermission requestPermission, final PickerContract.IPickerView view) {
RxPermissions rxPermissions = new RxPermissions((Activity) view);
boolean isPermissionsGranted =
rxPermissions
.isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (isPermissionsGranted) {
requestPermission.onRequestPermissionSuccess();
} else {
rxPermissions
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(@NonNull Boolean aBoolean) throws Exception {
if (aBoolean) {
requestPermission.onRequestPermissionSuccess();
} else {
view.showMessage(((Activity) view).getResources().getString(R.string.request_permission_fail));
}
}
});
}
}
示例8: onCreate
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ButterKnife.bind(this);
rxPermissions = new RxPermissions(this);
rxLocation = new RxLocation(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
rvNearbyRestaurant.setLayoutManager(linearLayoutManager);
// get users last known location
getLastKnownLocation(searchTerm);
endlessRecyclerViewScrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
offset = totalItemsCount;
loadData(searchTerm, lastKnownLocation, offset);
}
};
rvNearbyRestaurant.addOnScrollListener(endlessRecyclerViewScrollListener);
}
示例9: readPhonestate
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
/**
* 請求獲取手機狀態的權限
*/
public static void readPhonestate(final RequestPermission requestPermission, RxPermissions rxPermissions, RxErrorHandler errorHandler) {
//先確保是否已經申請過權限
boolean isPermissionsGranted =
rxPermissions
.isGranted(Manifest.permission.READ_PHONE_STATE);
if (isPermissionsGranted) {//已經申請過,直接執行操作
requestPermission.onRequestPermissionSuccess();
} else {//沒有申請過,則申請
rxPermissions
.request(Manifest.permission.READ_PHONE_STATE)
.subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
@Override
public void onNext(Boolean granted) {
if (granted) {
Timber.tag(TAG).d("request SEND_SMS success");
requestPermission.onRequestPermissionSuccess();
} else {
Timber.tag(TAG).e("request permissons failure");
}
}
});
}
}
示例10: callPhone
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
/**
* 請求打電話權限
*/
public static void callPhone(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
//先確保是否已經申請過權限
boolean isPermissionsGranted =
rxPermissions
.isGranted(Manifest.permission.CALL_PHONE);
if (isPermissionsGranted) {//已經申請過,直接執行操作
requestPermission.onRequestPermissionSuccess();
} else {//沒有申請過,則申請
rxPermissions
.request(Manifest.permission.CALL_PHONE)
.subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
@Override
public void onNext(Boolean granted) {
if (granted) {
Timber.tag(TAG).d("request SEND_SMS success");
requestPermission.onRequestPermissionSuccess();
} else {
view.showMessage("request permissons failure");
}
}
});
}
}
示例11: onCreate
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(Color.TRANSPARENT);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
// checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
// getWindow().setBackgroundDrawableResource(R.drawable.splash_bg);
RxPermissions rxPermissions = new RxPermissions(this);
rxPermissions.request(permissions)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
Log.d(TAG, "permission is all granted: " + aBoolean);
doNext();
}
});
}
示例12: takePhoto
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
private void takePhoto(final Uri outputUri) {
Observable<Boolean> permissionObservable = Observable.just(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
permissionObservable = new RxPermissions(this).request(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
permissionObservable.flatMap(new Function<Boolean, ObservableSource<Uri>>() {
@Override
public ObservableSource<Uri> apply(@NonNull Boolean granted) throws Exception {
if (!granted) {
return Observable.empty();
}
return RxGallery.photoCapture(MainActivity.this, outputUri).toObservable();
}
}).subscribe(new Consumer<Uri>() {
@Override
public void accept(Uri uri) throws Exception {
Toast.makeText(MainActivity.this, uri.toString(), Toast.LENGTH_LONG).show();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Toast.makeText(MainActivity.this, throwable.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
示例13: call
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
@Override
public void call(String phoneNumber, IPhoneCallBack callBack) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (mActivity.checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
callBack.onPhoneCallBack(ResourceUtils.getResources().getString(R.string.no_call_permission));
return;
}
}
RxPermissions rxPermissions = new RxPermissions(mActivity);
rxPermissions.request(Manifest.permission.CALL_PHONE)
.subscribe(granted -> {
if (granted) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phoneNumber));
mActivity.startActivity(intent);
} else {
callBack.onPhoneCallBack(ResourceUtils.getResources().getString(R.string.no_call_permission));
}
});
}
示例14: checkPermissions
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
@Override
public void checkPermissions(RxPermissions rxPermissions) {
addSubscribe(rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean granted) {
if (granted) {
mView.startDownloadService();
} else {
mView.showError("下載應用需要文件寫入權限哦~");
}
}
})
);
}
示例15: checkPermissions
import com.tbruyelle.rxpermissions2.RxPermissions; //導入依賴的package包/類
@Override
public void checkPermissions(RxPermissions rxPermissions) {
addSubscribe(rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean granted) {
if (granted) {
mView.startDownloadService();
} else {
mView.showErrorMsg("下載應用需要文件寫入權限哦~");
}
}
})
);
}