Example usage for android.content.pm PackageManager PERMISSION_GRANTED

List of usage examples for android.content.pm PackageManager PERMISSION_GRANTED

Introduction

In this page you can find the example usage for android.content.pm PackageManager PERMISSION_GRANTED.

Prototype

int PERMISSION_GRANTED

To view the source code for android.content.pm PackageManager PERMISSION_GRANTED.

Click Source Link

Document

Permission check result: this is returned by #checkPermission if the permission has been granted to the given package.

Usage

From source file:com.mercandalli.android.apps.files.user.LoginRegisterActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {

    if (requestCode == REQUEST_GET_ACCOUNT_PERMISSION && grantResults.length == 1
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        mShouldResolve = true;/*from  w  w w. ja  v  a2 s.  c  om*/
        mGoogleApiClient.connect();
    }

}

From source file:com.adafruit.bluefruit.le.connect.app.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case PERMISSION_REQUEST_FINE_LOCATION: {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Log.d(TAG, "Location permission granted");
            // Autostart scan
            autostartScan();//  w  w  w. jav a2s  .  c  om
            // Update UI
            updateUI();
        } else {
            final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Bluetooth Scanning not available");
            builder.setMessage(
                    "Since location access has not been granted, the app will not be able to scan for Bluetooth peripherals");
            builder.setPositiveButton(android.R.string.ok, null);
            builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                }

            });
            builder.show();
        }
        break;
    }
    default:
        break;
    }
}

From source file:abanoubm.dayra.main.Main.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == FOLDER_REQUEST) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Intent intent = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            intent.setDataAndType(Uri.fromFile(new File(Utility.getDayraFolder())), "*/*");
            startActivity(intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
        }/*from   www .j  av a 2s.  com*/

    } else if (requestCode == IMPORT_REQUEST) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
            importDB();

    }
}

From source file:cl.gisred.android.PowerOnActivity.java

private void verifPermisos() {
    if (ContextCompat.checkSelfPermission(PowerOnActivity.this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(PowerOnActivity.this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {

        } else {//from  www. jav a2 s  . com
            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(PowerOnActivity.this,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    Util.REQUEST_ACCESS_FINE_LOCATION);
        }
    } else {
        initGeoposition();
    }
}

From source file:com.alibaba.weex.extend.module.location.DefaultLocation.java

@Override
public void destroy() {
    WXLogUtils.d("into--[destroy]");
    if (mWXSDKInstance == null || mWXSDKInstance.isDestroy() || mLocationManager == null) {
        return;/*from w  w  w  . j  a  v a 2s .co m*/
    }

    if (mWXLocationListeners != null && mWXLocationListeners.size() > 0) {
        if (ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(),
                Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(),
                        Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            for (WXLocationListener listener : mWXLocationListeners) {
                if (listener != null) {
                    listener.destroy();
                    mLocationManager.removeUpdates(listener);
                }
            }
            mWXLocationListeners.clear();
        }
    }

    if (mRegisterSucCallbacks != null && mRegisterSucCallbacks.size() > 0) {
        Collection<WXLocationListener> values = mRegisterSucCallbacks.values();
        if (ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(),
                Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(),
                        Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            for (WXLocationListener listener : values) {
                listener.destroy();
                mLocationManager.removeUpdates(listener);
            }
            mRegisterSucCallbacks.clear();
        }
    }
}

From source file:com.esri.arcgisruntime.sample.editfeatureattachments.EditAttachmentActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    // If request is cancelled, the result arrays are empty.
    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        // Location permission was granted. This would have been triggered in response to failing to start the
        // LocationDisplay, so try starting this again.
        permissionsGranted = true;/*  www .  j av a2  s .c o m*/
        if (requestCode == requestCodeGallery) {
            selectAttachment();
        } else {
            fetchAttachmentAsync(listPosition, listView);
        }

    } else {
        // If permission was denied, show toast to inform user what was chosen. If LocationDisplay is started again,
        // request permission UX will be shown again, option should be shown to allow never showing the UX again.
        // Alternative would be to disable functionality so request is not shown again.
        Toast.makeText(EditAttachmentActivity.this,
                getResources().getString(R.string.storage_permission_denied), Toast.LENGTH_SHORT).show();
        permissionsGranted = false;

    }
}

From source file:cliq.com.cliqgram.fragments.CameraFragment.java

/**
 * Opens the camera specified by {@link CameraFragment#mCameraId}.
 *//*w  w w. j  ava 2 s . c  om*/
private void openCamera(int width, int height) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (getActivity()
                .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            requestCameraPermission();
            return;
        }
    }

    setUpCameraOutputs(width, height);
    configureTransform(width, height);
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
            throw new RuntimeException("Time out waiting to lock camera opening.");
        }
        manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
    }
}

From source file:co.taqat.call.CallActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, final int[] grantResults) {
    for (int i = 0; i < permissions.length; i++) {
        Log.i("[Permission] " + permissions[i] + " is "
                + (grantResults[i] == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
    }//from w w  w .j  av a2 s  .  c om

    switch (requestCode) {
    case PERMISSIONS_REQUEST_CAMERA:
        UIThreadDispatcher.dispatch(new Runnable() {
            @Override
            public void run() {
                acceptCallUpdate(grantResults[0] == PackageManager.PERMISSION_GRANTED);
            }
        });
        break;
    case PERMISSIONS_ENABLED_CAMERA:
        UIThreadDispatcher.dispatch(new Runnable() {
            @Override
            public void run() {
                disableVideo(grantResults[0] != PackageManager.PERMISSION_GRANTED);
            }
        });
        break;
    case PERMISSIONS_ENABLED_MIC:
        UIThreadDispatcher.dispatch(new Runnable() {
            @Override
            public void run() {
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    toggleMicro();
                }
            }
        });
        break;
    }
}

From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java

@TargetApi(16)
private void requestLocation() {

    // Check permission
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // ask for permission:
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                PERMISSION_ACCESS_FINE_LOCATION);
    } else {/*from w  ww .  j a  va  2s  . c o  m*/
        startLocationAccess();
    }

}

From source file:key.secretkey.SettingsActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case REQUEST_EXTERNAL_STORAGE: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            //                    getSshKey();
        }/*from   w w  w .  j a  v a 2 s . c  o  m*/
    }
    }
}