本文整理汇总了Java中android.support.v4.app.ActivityCompat.checkSelfPermission方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityCompat.checkSelfPermission方法的具体用法?Java ActivityCompat.checkSelfPermission怎么用?Java ActivityCompat.checkSelfPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.ActivityCompat
的用法示例。
在下文中一共展示了ActivityCompat.checkSelfPermission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startLocationUpdates
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
protected void startLocationUpdates() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_ACCESS_FINE_LOCATION);
Log.d(TAG, "Permission Not Granted");
}
} else {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
}
}
示例2: openCamera
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void openCamera(String cameraId) {
try {
// CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(cameraId);
// characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
if (ActivityCompat.checkSelfPermission(getContext(), permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
setUpCameraOutputs(cameraId, ttv_camera.getWidth(), ttv_camera.getHeight());
configureTransform(ttv_camera.getWidth(), ttv_camera.getHeight());
mCameraManager.openCamera(cameraId, mCameraDeviceStateCallback, mHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例3: setUpMap
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void setUpMap() {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED){
}else {
mapView.setMyLocationEnabled(true);
}
// mapView.getUiSettings().setMapToolbarEnabled(true);
mapView.getUiSettings().setIndoorLevelPickerEnabled(true);
mapView.getUiSettings().setAllGesturesEnabled(true);
if (cameraChangeListener != null){
mapView.setOnCameraChangeListener(cameraChangeListener);
}
setMyLocation();
mapView.setOnMapClickListener(this);
mapView.setOnMarkerDragListener(this);
mapView.setOnMyLocationButtonClickListener(this);
mapView.setOnMapLoadedCallback(this);
}
示例4: startLocationUpdates
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void startLocationUpdates() {
if (ActivityCompat.checkSelfPermission(getContext(),
Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
// Start listening for updates
LocationServices.FusedLocationApi.requestLocationUpdates(
googleApiClient,
locationSettingsHandler.getLocationRequest(),
this
).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status r) {
requestingLocationUpdates = true;
}
});
mapHandler.setupRunningMapUI();
mapHandler.startShowingLocation();
}
}
示例5: onConnected
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
loadingView.setVisibility(View.VISIBLE);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.GET_ACCOUNTS)) {
Toast.makeText(getApplicationContext(), getString(R.string.should_accept_permissions), Toast.LENGTH_LONG).show();
return;
// ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.GET_ACCOUNTS}, PERMISSION_REQUEST_GET_ACCOUNTS);
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.GET_ACCOUNTS}, PERMISSION_REQUEST_GET_ACCOUNTS);
}
return;
}
new Thread(new Runnable() {
@Override
public void run() {
DataManager.setGoogleAccountLink(true);
Drive.DriveApi.getAppFolder(mGoogleApiClient).listChildren(mGoogleApiClient).setResultCallback(connectDriveCallback);
}
}).start();
Person person = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
headerResult.removeProfile(0);
headerResult.addProfiles(new ProfileDrawerItem().withName(person.getDisplayName()).withEmail(Plus.AccountApi.getAccountName(mGoogleApiClient)).withIcon(person.getImage().getUrl()));
if (person.getCover() != null && person.getCover().getCoverPhoto() != null && person.getCover().getCoverPhoto().getUrl() != null)
headerResult.setHeaderBackground(new ImageHolder(person.getCover().getCoverPhoto().getUrl()));
drawer.removeItems(4, 11);
}
示例6: showCurrentLocation
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
public void showCurrentLocation() {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//WE CALL THE DIALOGBOX TO REQUEST FOR THE PERMISSIONS
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_LOCATION_PERMISSIONS);
}
googleMap.setMyLocationEnabled(true);
}
示例7: locationPermissions
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
public static void locationPermissions(Activity activity, GoogleMap googleMap) {
// Check if location request permission is granted
if (ActivityCompat.checkSelfPermission(activity.getApplicationContext(),
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// Ask permission
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_LOCATION);
}
}
示例8: checkLocationPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void checkLocationPermission() {
final String locationPermission = Manifest.permission.ACCESS_FINE_LOCATION;
try {
if (ActivityCompat.checkSelfPermission(this, locationPermission) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{locationPermission}, REQUEST_CODE_PERMISSION);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: getNoGrantedPermission
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/**
* @param activity
* @param isShouldRationale true: return no granted and shouldShowRequestPermissionRationale permissions, false:return no granted and !shouldShowRequestPermissionRationale
* @return
*/
public static ArrayList<String> getNoGrantedPermission(Activity activity, boolean isShouldRationale) {
ArrayList<String> permissions = new ArrayList<>();
for (int i = 0; i < requestPermissions.length; i++) {
String requestPermission = requestPermissions[i];
//TODO checkSelfPermission
int checkSelfPermission = -1;
try {
checkSelfPermission = ActivityCompat.checkSelfPermission(activity, requestPermission);
} catch (RuntimeException e) {
Toast.makeText(activity, "please open those permission", Toast.LENGTH_SHORT)
.show();
Log.e(TAG, "RuntimeException:" + e.getMessage());
return null;
}
if (checkSelfPermission != PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "getNoGrantedPermission ActivityCompat.checkSelfPermission != PackageManager.PERMISSION_GRANTED:" + requestPermission);
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, requestPermission)) {
Log.d(TAG, "shouldShowRequestPermissionRationale if");
if (isShouldRationale) {
permissions.add(requestPermission);
}
} else {
if (!isShouldRationale) {
permissions.add(requestPermission);
}
Log.d(TAG, "shouldShowRequestPermissionRationale else");
}
}
}
return permissions;
}
示例10: setupPermissions
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/**
* App Permissions for Audio
**/
private void setupPermissions() {
// If we don't have the record audio permission...
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
// And if we're on SDK M or later...
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Ask again, nicely, for the permissions.
String[] permissionsWeNeed = new String[]{ Manifest.permission.RECORD_AUDIO };
requestPermissions(permissionsWeNeed, MY_PERMISSION_RECORD_AUDIO_REQUEST_CODE);
}
} else {
// Otherwise, permissions were granted and we are ready to go!
mAudioInputReader = new AudioInputReader(mVisualizerView, this);
}
}
示例11: callPhone
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
public static void callPhone(Activity activity, String phoneNumber) {
if (activity != null && !TextUtils.isEmpty(phoneNumber)) {
if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)));
}
}
示例12: hasPermissions
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private boolean hasPermissions(Context context, String... permissions) {
if (context == null || permissions == null) {
throw new IllegalArgumentException("パーミッションチェックには、Contextとチェックしたいpermissionが必要です");
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
示例13: stopRequest
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
public void stopRequest(Context c) {
Log.i(TAG, "stopRequest: ");
if (ActivityCompat.checkSelfPermission(c, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(c, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
locMan.removeUpdates(locLis);
}
示例14: isPermissionGranted
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private boolean isPermissionGranted() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED ||
ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getContext(), "Permission denied, please enable permission", Toast.LENGTH_SHORT).show();
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
return false;
}
}
return true;
}
示例15: getExternalPhotoSimpleAdapter
import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private SimpleAdapter<Uri> getExternalPhotoSimpleAdapter() {
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
return ContentProviderSimpleAdapter.getExternalPhotoSimpleAdapter(getActivity());
} else {
requestPermissions(
new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_READ_EXTERNAL_ID);
}
return SimpleAdapter.Util.EMPTY_ADAPTER;
}