当前位置: 首页>>代码示例>>Java>>正文


Java ActivityCompat.checkSelfPermission方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:pmathew92,项目名称:MapsWithPlacesAutoComplete,代码行数:18,代码来源:MapsActivity.java

示例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();
        }
    }
 
开发者ID:vipycm,项目名称:mao-android,代码行数:22,代码来源:Camera2Fragment.java

示例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);

    }
 
开发者ID:fekracomputers,项目名称:MuslimMateAndroid,代码行数:24,代码来源:MapFragment.java

示例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();
    }
}
 
开发者ID:IrrilevantHappyLlamas,项目名称:Runnest,代码行数:22,代码来源:RunFragment.java

示例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);
}
 
开发者ID:JeanBarriere,项目名称:Note,代码行数:31,代码来源:MainActivity.java

示例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);
}
 
开发者ID:Balthair94,项目名称:AppGoogleMaps,代码行数:12,代码来源:MainActivity.java

示例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);
    }
}
 
开发者ID:a-deda,项目名称:share-location,代码行数:12,代码来源:PermissionChecker.java

示例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();
    }
}
 
开发者ID:TechIsFun,项目名称:RxJava2-weather-example,代码行数:11,代码来源:MainActivity.java

示例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;
}
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:45,代码来源:PermissionUtils.java

示例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);
    }
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:18,代码来源:VisualizerActivity.java

示例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)));
    }
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:9,代码来源:SystemUtils.java

示例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;
}
 
开发者ID:kwmt,项目名称:WebViewInputSample,代码行数:14,代码来源:FileChooserWebChromeClient.java

示例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);
}
 
开发者ID:Baleine82,项目名称:TrainPonctuality,代码行数:8,代码来源:LocationProxy.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:ascii_generate,代码行数:15,代码来源:FigletFragment.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:MainFragment.java


注:本文中的android.support.v4.app.ActivityCompat.checkSelfPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。