本文整理汇总了Java中permissions.dispatcher.NeedsPermission类的典型用法代码示例。如果您正苦于以下问题:Java NeedsPermission类的具体用法?Java NeedsPermission怎么用?Java NeedsPermission使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NeedsPermission类属于permissions.dispatcher包,在下文中一共展示了NeedsPermission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: chooseFile
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
public void chooseFile(Intent dataIntent) {
/* Check for network connectivity */
if (isConnectedToActiveNetwork(this)) {
// if upload was chosen from the app
if (dataIntent == null) {
// Use system file browser
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Choose the file to Upload.."), INTENT_FILE_REQUEST);
} else {
// If Intent received from implicit intent
onActivityResult(INTENT_FILE_REQUEST, RESULT_OK, dataIntent);
}
} else {
/* Show no network dialog */
NoNetworkDialogFragment noNetworkDialogFragment = new NoNetworkDialogFragment();
noNetworkDialogFragment.show(getSupportFragmentManager(), getString(R.string.no_net_dialog_fragment_tag));
}
}
示例2: takeAPhoto
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission({Manifest.permission.CAMERA})
void takeAPhoto() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(this.getPackageManager()) != null) {
Observable.just(this)
.observeOn(Schedulers.newThread())
.map((ctx) -> presenter.createImageFile(this))
.subscribe(photoFile -> {
Timber.d(Thread.currentThread().getName());
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID
+ ".provider", presenter.createImageFile(this));
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, TAKE_PHOTO);
}
}, t -> onLocationError());
}
}
示例3: setupHttpCachingTileServer
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
// Must be public to use PermissionsDispatcher
public void setupHttpCachingTileServer() {
final String tag = "setupHttpCachingTileServer - ";
final HttpCacheTileServer httpCacheTileServer = HttpCacheTileServer.getInstance();
httpCacheTileServer.init(getActivity(), SettingsUtils.getInstance().parseFromPreferencesMapCacheDiskUsageMax());
if (httpCacheTileServer.startServer()){
// Server in place, load page
final String url="file:///android_asset/index.html";
if (webView.getUrl()==null || webView.getUrl().isEmpty() || !webView.getUrl().equalsIgnoreCase(url)) {
webView.loadUrl("file:///android_asset/index.html");
// Flow will resume at: onPageFinished
}
}
}
示例4: setupLocationService
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
// Must be public to use PermissionsDispatcher
public void setupLocationService() {
final String tag="setupLocationService - ";
if (isAdded()) {
final Activity activity=getActivity();
if (activity!=null){
locationServiceConnection = new LocationServiceConnection((OwnLocationReceivedListener) this);
Intent serviceIntent = new Intent(activity,TrackService.class);
activity.startService(serviceIntent);
activity.bindService(new Intent(activity,TrackService.class), locationServiceConnection, Context.BIND_AUTO_CREATE);
} else {
Log.e(TAG,tag+"Activity is null.");
}
}
}
示例5: onInsertImageUploadClicked
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@SuppressLint("InlinedApi") // suppressed because PermissionsDispatcher handles API levels for us
@NeedsPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
public void onInsertImageUploadClicked(Action1<String> uploadDoneAction) {
mImageUploadDoneAction = uploadDoneAction;
Intent imagePickIntent = new Intent(Intent.ACTION_GET_CONTENT);
imagePickIntent.addCategory(Intent.CATEGORY_OPENABLE);
imagePickIntent.setType("image/*");
if (imagePickIntent.resolveActivity(mActivity.getPackageManager()) != null) {
startActivityForResult(imagePickIntent, REQUEST_CODE_IMAGE_PICK);
} else {
Toast.makeText(mActivity, R.string.intent_no_apps, Toast.LENGTH_SHORT).show();
}
}
示例6: loadArtworkView
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
public void loadArtworkView(final EMPlaylistManager.PlaylistItem currentItem) {
picasso.load(currentItem.getArtworkUrl()).transform(new BlurTransformer(currentItem.getArtworkUrl())).into(artworkView, new Callback() {
@Override
public void onSuccess() {
RotateAnimation ra = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
ra.setRepeatMode(Animation.INFINITE);
ra.setRepeatCount(Animation.INFINITE);
ra.setDuration(12000l);
ra.setInterpolator(new LinearInterpolator());
artworkView.startAnimation(ra);
}
@Override
public void onError() {
}
});
}
示例7: onUpdateAvailable
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission({
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_PHONE_STATE,
Manifest.permission.RECORD_AUDIO
}) void checkUpdate() {
//PgyUpdateManager.register(getActivity(), getString(R.string.file_provider));
PgyUpdateManager.register(getActivity(), getString(R.string.file_provider),
new UpdateManagerListener() {
@Override public void onUpdateAvailable(final String result) {
// 将新版本信息封装到AppBean中
final AppBean appBean = getAppBeanFromString(result);
new AlertDialog.Builder(getActivity()).setTitle("更新")
.setMessage(appBean.getReleaseNote())
.setNegativeButton("取消", null)
.setPositiveButton("下载", new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
startDownloadTask(getActivity(), appBean.getDownloadURL());
}
})
.show();
}
@Override public void onNoUpdateAvailable() {
ToastUtil.showText(getActivity(), "已经是最新版本了");
}
});
}
示例8: startCollectorService
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission({Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.READ_PHONE_STATE})
void startCollectorService() {
Log.d("startCollectorService(): Air plane mode off, starting service");
// create intent
final Intent intent = new Intent(this, CollectorService.class);
// pass means of transport inside intent
boolean gpsOptimizationsEnabled = MyApplication.getPreferencesProvider().getGpsOptimizationsEnabled();
MeansOfTransport selectedType = (gpsOptimizationsEnabled ? MeansOfTransport.Universal : MeansOfTransport.Fixed);
intent.putExtra(CollectorService.INTENT_KEY_TRANSPORT_MODE, selectedType);
// pass screen on mode
final String keepScreenOnMode = MyApplication.getPreferencesProvider().getCollectorKeepScreenOnMode();
intent.putExtra(CollectorService.INTENT_KEY_KEEP_SCREEN_ON_MODE, keepScreenOnMode);
// start service
ApkUtils.startServiceSafely(this, intent);
EventBus.getDefault().post(new CollectorStartedEvent(intent));
MyApplication.getAnalytics().sendCollectorStarted(IntentSource.User);
}
示例9: dispatchHandleAttachmentLink
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
public void dispatchHandleAttachmentLink(SubjectReport report) {
File baseDir =
new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
"E-class");
if (!baseDir.exists() && !baseDir.mkdirs()) {
throw new RuntimeException("No access to storage");
}
File destination = new File(baseDir, report.getName());
Intent intent = new Intent(this, AttachmentDownloaderService.class);
intent.putExtra(AttachmentDownloaderService.EXTRA_ASSIGNMENT_SUBJECT, report);
intent.putExtra(AttachmentDownloaderService.EXTRA_DESTINATION, destination.getPath());
this.startService(intent);
}
示例10: prepareSending
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
/**
* 检查VPN连接,并发送
*/
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
void prepareSending(final int resId) {
if (NetworkUtil.isVpnEnabled()) {
new AlertDialog.Builder(this)
.setTitle(getString(R.string.dialog_vpn_title))
.setMessage(getString(R.string.dialog_vpn_message))
.setPositiveButton(getString(R.string.dialog_vpn_button_close), null)
.setNegativeButton(getString(R.string.dialog_vpn_button_ignore), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sendFile(resId);
}
})
.show();
} else {
sendFile(resId);
}
}
示例11: initGoogleMap
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
void initGoogleMap() {
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(googleMap -> {
//noinspection MissingPermission
googleMap.setMyLocationEnabled(true);
binding.mapSearchView.bindData(placeMapList, placeMap -> {
LatLng latLng = new LatLng(placeMap.latitude, placeMap.longitude);
int duration = getResources().getInteger(R.integer.map_camera_move_mills);
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng), duration, null);
Marker marker = markers.get(placeMap.nameRes);
if (marker != null) marker.showInfoWindow();
});
binding.loadingView.setVisibility(View.GONE);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setIndoorEnabled(true);
googleMap.setBuildingsEnabled(true);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LAT_LNG_CENTER, DEFAULT_ZOOM));
UiSettings mapUiSettings = googleMap.getUiSettings();
mapUiSettings.setCompassEnabled(true);
renderMarkers(placeMapList, googleMap);
});
}
示例12: startLocationUpdates
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@SuppressWarnings("MissingPermission")
@NeedsPermission({Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION})
void startLocationUpdates() {
if (!isLocationPermissionsGranted()) {
return;
}
locationManager.startLocationUpdates(!isLocationSettingsCheckAsked);
isLocationSettingsCheckAsked = true;
}
示例13: call
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission(Manifest.permission.CALL_PHONE)
//在需要获取权限的地方注释
void call() {
Intent intent = new Intent(Intent.ACTION_CALL);
Uri data = Uri.parse("tel:" + "10086");
intent.setData(data);
try {
startActivity(intent);
} catch (SecurityException e) {
e.printStackTrace();
}
}
示例14: showCheckPermissionState
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
/**
* 这个方法中写正常的逻辑(假设有该权限应该做的事)
*/
@NeedsPermission({Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH,
Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION
, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
void showCheckPermissionState() {
//检查是否开启位置信息(如果没有开启,则无法扫描到任何蓝牙设备在6.0)
if (!LocationUtils.isGpsProviderEnabled(this)) {
showOpenLocationSettingDialog();
}
}
示例15: startService
import permissions.dispatcher.NeedsPermission; //导入依赖的package包/类
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
public void startService() {
serviceRunning = true;
plSwitch.start();
startService(new Intent(this, ClipboardService.class));
showAlert(R.string.message_service_enabled, R.color.colorAlertGreen, R.drawable.ic_check,
Constants.DURATION_SHORT);
}