Java 类android.support.v4.app.ActivityCompat 实例源码

项目:AndroidSdrRtlTuner    文件:SettingsFragment.java   
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

    // update the summeries:
    updateSummaries();

    // Screen Orientation:
    String screenOrientation = sharedPreferences.getString(getString(R.string.pref_screenOrientation), "auto");
    setScreenOrientation(screenOrientation);

    // check WRITE_EXTERNAL_STORAGE permission if logging is active:
    if(sharedPreferences.getBoolean(getString(R.string.pref_logging), false)) {
        if (ContextCompat.checkSelfPermission(this.getActivity(), "android.permission.WRITE_EXTERNAL_STORAGE")
                != PackageManager.PERMISSION_GRANTED) {
            // request permission:
            ActivityCompat.requestPermissions(this.getActivity(), new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"},
                    PERMISSION_REQUEST_LOGGING_WRITE_FILES);
        }
    }
}
项目:Android-Code-Demos    文件:RequestPermissions.java   
public static void requestRuntimePermission(Activity activity, String[] permissions,
                                            OnRequestPermissionsListener listener) {
    Activity topActivity = activity;
    if (null == topActivity) {
        return;
    }
    mListener = listener;
    List<String> permissionList = new ArrayList<>();
    for (String permission : permissions) {
        if (ContextCompat.checkSelfPermission(topActivity, permission)
                != PackageManager.PERMISSION_GRANTED) {

            permissionList.add(permission);
        }
    }
    if (!permissionList.isEmpty()) {
        ActivityCompat.requestPermissions(topActivity,
                permissionList.toArray(new String[permissionList.size()]),
                PERMISSION_REQUEST_CODE);
    } else {
        mListener.onGranted();
    }
}
项目:quire    文件:GroupChatFragment.java   
private void requestStoragePermissions() {
    if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        // Provide an additional rationale to the user if the permission was not granted
        // and the user would benefit from additional context for the use of the permission.
        // For example if the user has previously denied the permission.
        Snackbar.make(mRootLayout, "Storage access permissions are required to upload/download files.",
                Snackbar.LENGTH_LONG)
                .setAction("Okay", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                PERMISSION_WRITE_EXTERNAL_STORAGE);
                    }
                })
                .show();
    } else {
        // Permission has not been granted yet. Request it directly.
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                PERMISSION_WRITE_EXTERNAL_STORAGE);
    }
}
项目:KotlinStudy    文件:MainActivity.java   
private void requestPermissions(){
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            int permission = ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if(permission!= PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this,new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.LOCATION_HARDWARE,Manifest.permission.READ_PHONE_STATE,
                        Manifest.permission.WRITE_SETTINGS,Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.RECORD_AUDIO,Manifest.permission.READ_CONTACTS},0x0010);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:VEHICLE-APP    文件:MapsActivity.java   
private void requestPermissions() {
        boolean shouldProvideRationale =
                ActivityCompat.shouldShowRequestPermissionRationale(this,
                        android.Manifest.permission.ACCESS_COARSE_LOCATION);

        // Provide an additional rationale to the user. This would happen if the user denied the
        // request previously, but didn't check the "Don't ask again" checkbox.
        if (shouldProvideRationale) {

                Log.i(TAG, "Displaying permission rationale to provide additional context.");

        } else {
                Log.i(TAG, "Requesting permission");
                // Request permission. It's possible this can be auto answered if device policy
                // sets the permission in a given state or the user denied the permission
                // previously and checked "Never ask again".
                startLocationPermissionRequest();
        }
}
项目:yjPlay    文件:MainListInfoCustomActivity.java   
@Override
public void onBackPressed() {
    //获取数据返回获取
    long currPosition = exoPlayerManager.getCurrentPosition();
    if (exoPlayerManager.onBackPressed()) {//使用播放返回键监听
        isBack=true;
        Toast.makeText(MainListInfoCustomActivity.this, "返回", Toast.LENGTH_LONG).show();
        Intent intent = new Intent();
        intent.putExtra("isEnd", isEnd);
        intent.putExtra("currPosition", currPosition);
        Log.d(TAG, "sss:" + exoPlayerManager.getCurrentPosition());
        setResult(RESULT_OK, intent);
        ActivityCompat.finishAfterTransition(this);
    }

}
项目:nongbeer-mvp-android-demo    文件:MapActivity.java   
private Location getLastKnownLocation(){
    if( ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_COARSE_LOCATION ) != PackageManager.PERMISSION_GRANTED ){
        return null;
    }
    LocationManager locationManager =
            (LocationManager) this.getSystemService( LOCATION_SERVICE );
    List<String> providers = locationManager.getProviders( true );
    Location bestLocation = null;
    for( String provider : providers ){
        Location l = locationManager.getLastKnownLocation( provider );
        if( l == null ){
            continue;
        }
        if( bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy() ){
            bestLocation = l; // Found best last known location;
        }
    }
    return bestLocation;
}
项目:Tess-TwoDemo    文件:CameraActivity.java   
/********************************** 以下是权限检查部分 ********************************/
private void checkPermission(){
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
            == PackageManager.PERMISSION_GRANTED) {
        mCameraView.start();
    } else if (ActivityCompat.shouldShowRequestPermissionRationale(this,
            Manifest.permission.CAMERA)) {
        ConfirmationDialogFragment
                .newInstance(R.string.camera_permission_confirmation,
                        new String[]{Manifest.permission.CAMERA},
                        REQUEST_CAMERA_PERMISSION,
                        R.string.camera_permission_not_granted)
                .show(getSupportFragmentManager(), FRAGMENT_DIALOG);
    } else {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA},
                REQUEST_CAMERA_PERMISSION);
    }
}
项目:FireFiles    文件:BaseActivity.java   
protected void requestStoragePermissions() {
    if(PermissionUtil.hasStoragePermission(this)) {
        again();
    } else {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            Utils.showRetrySnackBar(this, "Storage permissions are needed for Exploring.", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ActivityCompat.requestPermissions(BaseActivity.this, storagePermissions, REQUEST_STORAGE);
                }
            });
        } else {
            ActivityCompat.requestPermissions(this, storagePermissions, REQUEST_STORAGE);
        }
    }
}
项目:AndroidBlueprints    文件:SplashActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Utils.hasLollipop()) requestWindowFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    super.onCreate(savedInstanceState);

    if (Utils.hasLollipop()) {
        getWindow().setExitTransition(new Fade());
    }

    //TODO: Remove after evaluation testing
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    Intent intent = new Intent(this, MainActivity.class);
    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this);
    ActivityCompat.startActivity(this, intent, options.toBundle());
    ActivityCompat.finishAfterTransition(this);
}
项目:P2Video-master    文件:MainActivity.java   
private void cheseFile() {
    int checkCode = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int checkRead = ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.READ_EXTERNAL_STORAGE);
    //如果拒绝
    if (checkCode== PackageManager.PERMISSION_DENIED||checkRead==PackageManager.PERMISSION_DENIED){
        //申请权限
        if (checkCode==PackageManager.PERMISSION_DENIED){
            ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},100);
        }
        if (checkRead==PackageManager.PERMISSION_DENIED){
            ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},101);
        }
    }else if (checkCode==PackageManager.PERMISSION_GRANTED){
        if (mSelected!=null&&mSelected.size()>0)
        mSelected.clear();
        CANPLAY=false;
        doSomething();
    }
}
项目:GogoNew    文件:MapsActivity.java   
private void requestPermissions() {
        boolean shouldProvideRationale =
                ActivityCompat.shouldShowRequestPermissionRationale(this,
                        android.Manifest.permission.ACCESS_COARSE_LOCATION);

        // Provide an additional rationale to the user. This would happen if the user denied the
        // request previously, but didn't check the "Don't ask again" checkbox.
        if (shouldProvideRationale) {

                Log.i(TAG, "Displaying permission rationale to provide additional context.");

        } else {
                Log.i(TAG, "Requesting permission");
                // Request permission. It's possible this can be auto answered if device policy
                // sets the permission in a given state or the user denied the permission
                // previously and checked "Never ask again".
                startLocationPermissionRequest();
        }
}
项目:FinalProject    文件:ActivityUtils.java   
private static boolean isReadStoragePermissionGranted(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Timber.d("Permission is granted");
            return true;
        } else {

            Timber.d("Permission is revoked");
            ActivityCompat.requestPermissions(activity,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    activity.getResources().getInteger(R.integer.read_external_storage_request));
            return false;
        }
    } else { //permission is automatically granted on sdk<23 upon installation
        Timber.d("Permission is granted");
        return true;
    }
}
项目:UpdateLibrary    文件:MainActivity.java   
/**
 * 更新Dialog
 *
 * @param url
 * @param version
 * @param desc
 * @param force
 */
private void showUpdateDialog(String url, String version, String desc, boolean force) {
    if (updateDialog == null) {
        updateDialog = new UpdateDialog(mContext);
        updateDialog.setValue(url, version, desc, force);
        updateDialog.setOnClickUpdateListener(() -> {
            updateDialog.cancel();
            if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions((Activity) mContext, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_WRITE_STORAGE);
            } else {
                updateDialog.onClickUpdate();
            }
        });
    }
    updateDialog.show();
}
项目:Hands-On-Android-UI-Development    文件:CaptureClaimActivity.java   
public void onAttachClick() {
    final int permissionStatus = ContextCompat.checkSelfPermission(
            this,
            Manifest.permission.READ_EXTERNAL_STORAGE
    );

    if (permissionStatus != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(
                this,
                new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                REQUEST_ATTACH_PERMISSION
        );

        return;
    }

    final Intent attach = new Intent(Intent.ACTION_GET_CONTENT)
            .addCategory(Intent.CATEGORY_OPENABLE)
            .setType("*/*");

    startActivityForResult(attach, REQUEST_ATTACH_FILE);
}
项目:MOAAP    文件:MainActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_main);

    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {
        Log.i("permission", "request READ_EXTERNAL_STORAGE");
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA);
    }else {
        Log.i("permission", "READ_EXTERNAL_STORAGE already granted");
        camera_granted = true;
    }

    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.main_activity_surface_view);
    mOpenCvCameraView.setCvCameraViewListener(this);
}
项目:ElephantAsia    文件:AddElephantActivity.java   
public void onAddDocumentClick() {
  pickImageDialog = new PickImageDialogBuilder(this)
      .build()
      .setListener(new PickImageDialog.Listener() {
        @Override
        public void execute(Intent intent, int requestCode) {
          if (requestCode == REQUEST_CAPTURE_PHOTO) {
            if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
              ActivityCompat.requestPermissions(AddElephantActivity.this, new String[]{Manifest.permission.CAMERA}, 0);
            } else {
              startActivityForResult(intent, requestCode);
            }
          } else {
            startActivityForResult(intent, requestCode);
          }
        }
      })
      .setCaptureCode(REQUEST_CAPTURE_PHOTO)
      .setImportCode(REQUEST_IMPORT_PHOTO)
      .load();
  pickImageDialog.show();
}
项目:bridgefy-android-samples    文件:DevicesActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_devices);
    ButterKnife.bind(this);

    // initialize the DevicesAdapter and the RecyclerView
    devicesAdapter = new DevicesAdapter();
    devicesRecyclerView.setAdapter(devicesAdapter);
    devicesRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    // check that we have Location permissions
    if (ContextCompat.checkSelfPermission(getApplicationContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        initializeBridgefy();
    } else {
        ActivityCompat.requestPermissions(this,
                new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 0);
    }
}
项目:Android-SmartWebView    文件:MainActivity.java   
public void get_file(){
    String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};

    //Checking for storage permission to write images for upload
    if (ASWP_FUPLOAD && ASWP_CAMUPLOAD && !check_permission(2) && !check_permission(3)) {
        ActivityCompat.requestPermissions(MainActivity.this, perms, file_perm);

    //Checking for WRITE_EXTERNAL_STORAGE permission
    } else if (ASWP_FUPLOAD && !check_permission(2)) {
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, file_perm);

    //Checking for CAMERA permissions
    } else if (ASWP_CAMUPLOAD && !check_permission(3)) {
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, file_perm);
    }
}
项目:wirtualnaApteczka    文件:LogInActivity.java   
private void verifyNecessaryPermissions() {
    int permissionCheckCamera = ContextCompat.checkSelfPermission(getApplicationContext(),
            Manifest.permission.CAMERA);

    if (permissionCheckCamera != PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.CAMERA, Manifest.permission.CAMERA},
                AppConstants.PERMISSION_REQUEST);
    }

    int permissionCheckInternet = ContextCompat.checkSelfPermission(getApplicationContext(),
            Manifest.permission.INTERNET);

    if (permissionCheckInternet != PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.INTERNET, Manifest.permission.INTERNET},
                AppConstants.PERMISSION_REQUEST);
    }
}
项目:iSPY    文件:MyLocation.java   
private void getCurrentLocation() {
    mMap.clear();
    if(ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_COARSE_LOCATION)!=PackageManager.PERMISSION_GRANTED )
    {
        //Creating a location object
        return ;}
    Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
    if (location != null) {
        //Getting longitude and latitude
        longitude = location.getLongitude();
        latitude = location.getLatitude();

        //moving the map to location
        moveMap();
    }
}
项目:text_converter    文件:BarCodeCodecFragment.java   
private void decodeImage() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        int result = ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE);
        if (result != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(getContext(), R.string.read_permission_msg, Toast.LENGTH_SHORT).show();
            String[] permissions = {Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE};
            requestPermissions(permissions, REQUEST_READ_EXTERNAL_STORAGE);
            return;
        }
    }

    try {
        Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
        getIntent.setType("image/*");

        Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        pickIntent.setType("image/*");

        Intent chooserIntent = Intent.createChooser(getIntent, getString(R.string.select_image));
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});

        startActivityForResult(chooserIntent, REQUEST_PICK_IMAGE);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:mupdf-android-viewer-mini    文件:LibraryActivity.java   
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* Hide 'home' icon on old themes */
    getActionBar().setDisplayShowHomeEnabled(false);

    prefs = getPreferences(Context.MODE_PRIVATE);

    topDirectory = Environment.getExternalStorageDirectory();
    currentDirectory = new File(prefs.getString("currentDirectory", topDirectory.getAbsolutePath()));

    adapter = new ArrayAdapter<Item>(this, android.R.layout.simple_list_item_1);
    setListAdapter(adapter);

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST);
}
项目:Facebook-Video-Downloader    文件:HomeFragment.java   
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_PERMISSION_SETTING) {
        if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            //Got Permission
            Toast.makeText(getActivity(),"Permissions Granted",Toast.LENGTH_LONG).show();
        }
    }
}
项目:SciChart.Android.Examples    文件:MailUtils.java   
private static boolean askForPermissions(Activity activity, @NonNull String[] permissions) {
    boolean hasPermissions = true;

    for (String permission : permissions) {
        hasPermissions &= ActivityCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_GRANTED;
    }

    if (!hasPermissions) {
        ActivityCompat.requestPermissions(activity, permissions, EMAIL_PERMISSIONS_REQUEST);
    }

    return hasPermissions;
}
项目:Bluetooth-send    文件:BluetoothDevices.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bluetooth_devices);
    initializeScreen();

    //check if the device has a bluetooth or not
    //and show Toast message if it does't have
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    bluetoothDevicesAdapter = new BluetoothDevicesAdapter(this, bluetoothDevicesNamesList);

    if (mBluetoothAdapter == null) {
        Toast.makeText(this, R.string.does_not_have_bluetooth, Toast.LENGTH_LONG).show();
        finish();
    } else if (!mBluetoothAdapter.isEnabled()) {
        Intent enableIntentBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntentBluetooth, REQUEST_ENABLE_BT);
    } else if (mBluetoothAdapter.isEnabled()) {
        PairedDevicesList();
    }

    setBroadCastReceiver();

    //request location permission for bluetooth scanning for android API 23 and above
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_ENABLE_FINE_LOCATION);


    //press the button to start search new Devices
    searchForNewDevices.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchForNewDevices.setEnabled(false);
            bluetoothDevicesAdapter.clear();
            PairedDevicesList();
            NewDevicesList();
        }
    });

}
项目:TestChat    文件:ImageDisplayActivity.java   
public static void start(final Activity activity, final View view, final String url) {
        Intent imageIntent = new Intent(activity, ImageDisplayActivity.class);
        imageIntent.putExtra("name", "photo");
        imageIntent.putExtra("url", url);
        LogUtil.e("启动图片浏览界面11");
        ActivityCompat.startActivity(activity, imageIntent, ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, "photo").toBundle());
}
项目:Runnest    文件:ChallengeActivity.java   
/**
 * This check is necessary only with Android 6.0+ and/or SDK 22+
 */
private boolean checkPermission() {
    int fineLocation = ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);

    if (fineLocation != PackageManager.PERMISSION_GRANTED) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                    PERMISSION_REQUEST_CODE_FINE_LOCATION);
        }
        return false;
    } else {
        return true;
    }
}
项目:DizzyPassword    文件:RxFingerPrinter.java   
@TargetApi(Build.VERSION_CODES.M)
public void startListening(FingerprintManager.CryptoObject cryptoObject) {
    //android studio 上,没有这个会报错
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT)
            != PackageManager.PERMISSION_GRANTED) {
        throw new FPerException(PERMISSION_DENIED_ERROE);
    }
    manager.authenticate(cryptoObject, null, 0, mSelfCancelled, null);
}
项目:Vienna    文件:MainActivity.java   
@TargetApi(Build.VERSION_CODES.M)
private void initPermission() {
  if (ContextCompat.checkSelfPermission(this,
      android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this,
        new String[]{
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.RECORD_AUDIO
        },
        MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
  }
}
项目:NFC-UID-Emulator    文件:MainActivity.java   
/** 寫入資料**/
public void writeInfo(String fileName, String strWrite) {
    //WRITE_EXTERNAL_STORAGE
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
    }
    try {

        String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath();
        String savePath = fullPath + File.separator + "/" + fileName;

        File file = new File(savePath);

        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(strWrite);

        bw.close();

    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:trust-wallet-android    文件:BarcodeCaptureActivity.java   
private void requestCameraPermission() {
    Log.w(TAG, "Camera permission is not granted. Requesting permission");

    final String[] permissions = new String[]{Manifest.permission.CAMERA};

    if (!ActivityCompat.shouldShowRequestPermissionRationale(this,
            Manifest.permission.CAMERA)) {
        ActivityCompat.requestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM);
    }
}
项目:FingerprintDemo    文件:FingerprintHelper.java   
public void startAuth(FingerprintManager manager,
                      FingerprintManager.CryptoObject cryptoObject) {

    cancellationSignal = new CancellationSignal();

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.USE_FINGERPRINT) !=
            PackageManager.PERMISSION_GRANTED) {
        return;
    }
    manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
}
项目:Cluttr    文件:MainActivity.java   
public boolean requestPerms() {
    if ((ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
            || ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        Log.d(Util.LOG_TAG, "Requesting I/O permissions");
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE}, Util.PERMISSION_REQUEST_STORAGE);
        return false;
    } else {
        Log.d(Util.LOG_TAG, "Permissions already granted, loading media");
        return true;
    }
}
项目:Croprotector    文件:WayPointActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // When the compile and target version is higher than 22, please request the
    // following permissions at runtime to ensure the
    // SDK work well.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.VIBRATE,
                        Manifest.permission.INTERNET, Manifest.permission.ACCESS_WIFI_STATE,
                        Manifest.permission.WAKE_LOCK, Manifest.permission.ACCESS_COARSE_LOCATION,
                        Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.CHANGE_WIFI_STATE, Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS,
                        Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.SYSTEM_ALERT_WINDOW,
                        Manifest.permission.READ_PHONE_STATE,
                }
                , 1);
    }

    setContentView(R.layout.activity_way_point);

    IntentFilter filter = new IntentFilter();
    filter.addAction(DJIDemoApplication.FLAG_CONNECTION_CHANGE);
    registerReceiver(mReceiver, filter);

    mapView = (MapView) findViewById(R.id.map);
    mapView.onCreate(savedInstanceState);

    initMapView();
    initUI();
    addListener();

}
项目:schulcloud-mobile-android    文件:CalendarContentUtil.java   
/**
 * deletes a event in the local android event db for a given uid (the _id property of the event-model)
 *
 * @param uid {String} - a uid of a event which will be deleted
 * @return {Integer} - the id of the deleted event
 */
public Integer deleteEventByUid(String uid) {
    if (ActivityCompat.checkSelfPermission(this.context, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
        PermissionsUtil.checkPermissions(CALENDAR_PERMISSION_CALLBACK_ID, (Activity) this.context, Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR);
        return -1;
    }


    Uri uri = Events.CONTENT_URI;
    String whereQuery = "(" + Events.UID_2445 + " = \'" + uid + "\')";
    return this.contentResolver.delete(uri, whereQuery, null);
}
项目:AR    文件:RequestPermissionsActivity.java   
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == REQUEST_PERMISSION) {
        // for each permission check if the user granted/denied them
        // you may want to group the rationale in a single dialog,
        // this is just an example
        int len = permissions.length;
        for (int i = 0; i < len; i++) {
            String permission = permissions[i];
            if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                // user rejected the permission
                boolean showRationale = ActivityCompat.shouldShowRequestPermissionRationale(RequestPermissionsActivity.this, permission );
                if (! showRationale) {
                    // user also CHECKED "never ask again"
                    // you can either enable some fall back,
                    // disable features of your app
                    // or open another dialog explaining
                    // again the permission and directing to
                    // the app setting

                } else if (Manifest.permission.WRITE_CONTACTS.equals(permission)) {
                    // todo define strings
                    showRationale(permission, R.string.permission_denied_contacts);
                    // user did NOT check "never ask again"
                    // this is a good place to explain the user
                    // why you need the permission and ask if he wants
                    // to accept it (the rationale)
                }
                //else if ( /* possibly check more permissions...*/ ) {}
            }
        }
    }
}
项目:yjPlay    文件:EncryptedVideoActivity.java   
@Override
public void onBackPressed() {
    if (exoPlayerManager.onBackPressed()) {
        ActivityCompat.finishAfterTransition(this);
        exoPlayerManager.onDestroy();
    }
}
项目:Camera-Roll-Android-App    文件:ItemActivity.java   
public void setResultAndFinish() {
    isReturning = true;
    Intent data = new Intent();
    data.setAction(SHARED_ELEMENT_RETURN_TRANSITION);
    data.putExtra(AlbumActivity.ALBUM_PATH, album.getPath());
    data.putExtra(AlbumActivity.EXTRA_CURRENT_ALBUM_POSITION, viewPager.getCurrentItem());
    setResult(RESULT_OK, data);
    ActivityCompat.finishAfterTransition(this);
}
项目:FaceFilter    文件:FaceFilterActivity.java   
/**
 * Handles the requesting of the camera permission.  This includes
 * showing a "Snackbar" message of why the permission is needed then
 * sending the request.
 */
private void requestCameraPermission() {
    Log.w(TAG, "Camera permission is not granted. Requesting permission");

    final String[] permissions = new String[]{Manifest.permission.CAMERA};

    if (!ActivityCompat.shouldShowRequestPermissionRationale(this,
            Manifest.permission.CAMERA)) {
        ActivityCompat.requestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM);
        return;
    }

    final Activity thisActivity = this;

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ActivityCompat.requestPermissions(thisActivity, permissions,
                    RC_HANDLE_CAMERA_PERM);
        }
    };

    Snackbar.make(mGraphicOverlay, R.string.permission_camera_rationale,
            Snackbar.LENGTH_INDEFINITE)
            .setAction(R.string.ok, listener)
            .show();
}