當前位置: 首頁>>代碼示例>>Java>>正文


Java RxPermissions類代碼示例

本文整理匯總了Java中com.tbruyelle.rxpermissions.RxPermissions的典型用法代碼示例。如果您正苦於以下問題:Java RxPermissions類的具體用法?Java RxPermissions怎麽用?Java RxPermissions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RxPermissions類屬於com.tbruyelle.rxpermissions包,在下文中一共展示了RxPermissions類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: callPhone

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
/**
     * 請求打電話權限
     */
    public static void callPhone(final RequestPermission requestPermission, RxPermissions rxPermissions, final BaseView view, RxErrorHandler errorHandler) {
//先確保是否已經申請過權限
        boolean isPermissionsGranted =
                rxPermissions
                        .isGranted(Manifest.permission.CALL_PHONE);

        if (isPermissionsGranted) {//已經申請過,直接執行操作
            requestPermission.onRequestPermissionSuccess();
        } else {//沒有申請過,則申請
            rxPermissions
                    .request(Manifest.permission.CALL_PHONE)
                    .compose(PermissionUtil.<Boolean>bindToLifecycle(view))//使用RXlifecycle,使subscription和activity一起銷毀
                    .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");
                            }
                        }
                    });
        }
    }
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:29,代碼來源:PermissionUtil.java

示例2: _getPermission

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
private void _getPermission() {
    final File dir = new File(FileDownloader.getDownloadDir());
    if (!dir.exists() || !dir.isDirectory()) {
        dir.delete();
        new RxPermissions(this).request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
                .subscribe(new Action1<Boolean>() {
                    @Override
                    public void call(Boolean granted) {
                        if (granted) {
                            dir.mkdirs();
                        } else {
                            SnackbarUtils.showSnackbar(HomeActivity.this, "下載目錄創建失敗", true);
                        }
                    }
                });
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:HomeActivity.java

示例3: onClick

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
@Override
public void onClick(DialogInterface dialogInterface, int which) {
    new RxPermissions(IndexWebActivityNew.this)
            .request(Manifest.permission.READ_PHONE_STATE, Manifest.permission.CALL_PHONE)//打電話的權限
            .subscribe(granted -> {
                if (granted) {
                    startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)));
                    AddCallRecordLoader addCallRecordLoader = new AddCallRecordLoader();

                    try {
                        addCallRecordLoader.addCallRecord(IndexWebActivityNew.this);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    DialogUtil.toastForShort(context, "請同意我們的權限,才能提供服務");
                }
            });
}
 
開發者ID:AlpacaNotSheep,項目名稱:hybrid,代碼行數:20,代碼來源:IndexWebActivityNew.java

示例4: externalStorage

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
/**
 * 請求外部存儲的權限
 */
public static void externalStorage(final RequestPermission requestPermission, RxPermissions rxPermissions, final BaseView view, RxErrorHandler errorHandler) {
    //先確保是否已經申請過攝像頭,和寫入外部存儲的權限
    boolean isPermissionsGranted =
            rxPermissions
                    .isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (isPermissionsGranted) {//已經申請過,直接執行操作
        requestPermission.onRequestPermissionSuccess();
    } else {//沒有申請過,則申請
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                    @Override
                    public void onNext(Boolean granted) {
                        if (granted) {
                            Timber.tag(TAG).d("request WRITE_EXTERNAL_STORAGE and CAMERA success");
                            requestPermission.onRequestPermissionSuccess();
                        } else {
                            view.showMessage("request permissons failure");
                        }
                    }
                });
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:PermissionUtil.java

示例5: sendSms

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
/**
     * 請求發送短信權限
     */
    public static void sendSms(final RequestPermission requestPermission, RxPermissions rxPermissions, final BaseView 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");
                            }
                        }
                    });
        }
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:PermissionUtil.java

示例6: callPhone

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
/**
     * 請求打電話權限
     */
    public static void callPhone(final RequestPermission requestPermission, RxPermissions rxPermissions, final BaseView 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");
                            }
                        }
                    });
        }
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:PermissionUtil.java

示例7: readPhonestate

import com.tbruyelle.rxpermissions.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");
                            }
                        }
                    });
        }
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:PermissionUtil.java

示例8: onStart

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
@Override
protected void onStart() {
    super.onStart();
    RxPermissions
            .getInstance(this)
            .request(Manifest.permission.ACCESS_FINE_LOCATION)
            .subscribe(new Action1<Boolean>() {
                @Override
                public void call(Boolean granted) {
                    if (granted) {
                        onLocationPermissionGranted();
                    } else {
                        Toast.makeText(BaseActivity.this, "Sorry, no demo without permission...", Toast.LENGTH_SHORT).show();
                    }
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:BaseActivity.java

示例9: externalStorage

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
/**
 * 請求外部存儲的權限
 */
public static void externalStorage(final RequestPermission requestPermission, RxPermissions rxPermissions, final BaseView view, RxErrorHandler errorHandler) {
    //先確保是否已經申請過攝像頭,和寫入外部存儲的權限
    boolean isPermissionsGranted =
            rxPermissions
                    .isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (isPermissionsGranted) {//已經申請過,直接執行操作
        requestPermission.onRequestPermissionSuccess();
    } else {//沒有申請過,則申請
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .compose(PermissionUtil.<Boolean>bindToLifecycle(view))//使用RXlifecycle,使subscription和activity一起銷毀
                .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                    @Override
                    public void onNext(Boolean granted) {
                        if (granted) {
                            Timber.tag(TAG).d("request WRITE_EXTERNAL_STORAGE and CAMERA success");
                            requestPermission.onRequestPermissionSuccess();
                        } else {
                            view.showMessage("request permissons failure");
                        }
                    }
                });
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:29,代碼來源:PermissionUtil.java

示例10: sendSms

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
/**
     * 請求發送短信權限
     */
    public static void sendSms(final RequestPermission requestPermission, RxPermissions rxPermissions, final BaseView view, RxErrorHandler errorHandler) {
//先確保是否已經申請過權限
        boolean isPermissionsGranted =
                rxPermissions
                        .isGranted(Manifest.permission.SEND_SMS);

        if (isPermissionsGranted) {//已經申請過,直接執行操作
            requestPermission.onRequestPermissionSuccess();
        } else {//沒有申請過,則申請
            rxPermissions
                    .request(Manifest.permission.SEND_SMS)
                    .compose(PermissionUtil.<Boolean>bindToLifecycle(view))//使用RXlifecycle,使subscription和activity一起銷毀
                    .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");
                            }
                        }
                    });
        }
    }
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:29,代碼來源:PermissionUtil.java

示例11: externalStorage

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
/**
 * 請求外部存儲的權限
 */
public static void externalStorage(final RequestPermission requestPermission, RxPermissions rxPermissions, final BaseView view, RxErrorHandler errorHandler) {
    //先確保是否已經申請過攝像頭,和寫入外部存儲的權限
    boolean isPermissionsGranted =rxPermissions
                    .isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (isPermissionsGranted) {//已經申請過,直接執行操作
        requestPermission.onRequestPermissionSuccess();
    } else {//沒有申請過,則申請
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                    @Override
                    public void onNext(Boolean granted) {
                        if (granted) {
                            Timber.tag(TAG).d("request WRITE_EXTERNAL_STORAGE and CAMERA success");
                            requestPermission.onRequestPermissionSuccess();
                        } else {
                            view.showMessage("request permissons failure");
                        }
                    }
                });
    }
}
 
開發者ID:Wan7451,項目名稱:mvparms,代碼行數:27,代碼來源:PermissionUtil.java

示例12: reactionToFABClick

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
private void reactionToFABClick() {
    RxPermissions permissions = new RxPermissions(getActivity());
    permissions
            .request(Manifest.permission.CAMERA,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)
            .subscribe(new Action1<Boolean>() {
                @Override
                public void call(Boolean aBoolean) {
                    if (aBoolean) {
                        openGallery();
                    } else {
                        Toast.makeText(getContext(), "同意授權相機和讀取存儲卡內容才能使用搭配功能", Toast.LENGTH_SHORT).show();
                    }
                }
            });

}
 
開發者ID:Sugarya,項目名稱:Closet,代碼行數:19,代碼來源:HomeFragment.java

示例13: onItemClick

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
@OnClick(R.id.container_footer_add)
void onItemClick() {
    rx.Observable<Boolean> observable;
    final Context context;
    if (mCurrentFragment != null) {
        observable = new RxPermissions(mCurrentFragment.getActivity())
                .request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA);
        context = mCurrentFragment.getContext();
    } else {
        context = mCurrentActivity;
        observable = new RxPermissions(mCurrentActivity)
                .request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA);
    }

    observable.subscribe(new Action1<Boolean>() {
        @Override
        public void call(Boolean granted) {
            if (granted) {
                openGalleryWrapper();
            } else {
                Toast.makeText(context, "相冊開啟需要獲取權限", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
 
開發者ID:Sugarya,項目名稱:SugarPhotoPicker,代碼行數:26,代碼來源:SelectPhotoRecyclerView.java

示例14: initView

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
@Override
public void initView(Bundle savedInstanceState) {
    Observable.timer(2000, TimeUnit.MILLISECONDS)
            .compose(RxPermissions.getInstance(this).ensureEach(Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA,
                    Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.ACCESS_COARSE_LOCATION))
            .compose(RxUtil.rxSchedulerHelper())
            .subscribe(permission -> {
                if (permission.granted) {
                    startActivity(ZhihuMainActivity.class);
                    finish();
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:FlashActivity.java

示例15: launchCamera

import com.tbruyelle.rxpermissions.RxPermissions; //導入依賴的package包/類
/**
 * 請求攝像頭權限
 */
public static void launchCamera(final RequestPermission requestPermission, RxPermissions rxPermissions, final BaseView view, RxErrorHandler errorHandler) {
    //先確保是否已經申請過攝像頭,和寫入外部存儲的權限
    boolean isPermissionsGranted =
            rxPermissions
                    .isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE) &&
                    rxPermissions
                            .isGranted(Manifest.permission.CAMERA);

    if (isPermissionsGranted) {//已經申請過,直接執行操作
        requestPermission.onRequestPermissionSuccess();
    } else {//沒有申請過,則申請
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE
                        , Manifest.permission.CAMERA)
                .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                    @Override
                    public void onNext(Boolean granted) {
                        if (granted) {
                            Timber.tag(TAG).d("request WRITE_EXTERNAL_STORAGE and CAMERA success");
                            requestPermission.onRequestPermissionSuccess();
                        } else {
                            view.showMessage("request permissons failure");
                        }
                    }
                });
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:PermissionUtil.java


注:本文中的com.tbruyelle.rxpermissions.RxPermissions類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。