Example usage for android.content.pm PackageManager PERMISSION_DENIED

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

Introduction

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

Prototype

int PERMISSION_DENIED

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

Click Source Link

Document

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

Usage

From source file:org.totschnig.myexpenses.dialog.DialogUtils.java

public static RadioGroup.OnCheckedChangeListener buildCalendarRestoreStrategyChangedListener(
        final ProtectedFragmentActivity context, final CalendarRestoreStrategyChangedListener listener) {
    return new RadioGroup.OnCheckedChangeListener() {
        @Override/*from  w  ww. jav  a2  s.co  m*/
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.restore_calendar_handling_backup
                    || checkedId == R.id.restore_calendar_handling_configured) {
                if (ContextCompat.checkSelfPermission(context,
                        Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_DENIED) {
                    ActivityCompat.requestPermissions(context,
                            new String[] { Manifest.permission.WRITE_CALENDAR },
                            ProtectionDelegate.PERMISSIONS_REQUEST_WRITE_CALENDAR);
                }
            }
            listener.onCheckedChanged();
        }
    };
}

From source file:org.thaliproject.nativetest.app.ConnectionEngine.java

@Override
public boolean onPermissionCheckRequired(String permission) {
    int permissionCheck = PackageManager.PERMISSION_DENIED;

    if (mActivity != null) {
        permissionCheck = ContextCompat.checkSelfPermission(mActivity, permission);
        Log.i(TAG, "onPermissionCheckRequired: " + permission + ": " + permissionCheck);

        if (permissionCheck == PackageManager.PERMISSION_DENIED) {
            requestPermission(permission);
        }// w  w w .  j  a v a 2  s . co m
    } else {
        Log.e(TAG, "onPermissionCheckRequired: The activity is null");
    }

    return (permissionCheck == PackageManager.PERMISSION_GRANTED);
}

From source file:org.wso2.iot.agent.activities.AlreadyRegisteredActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (requestCode == 110) {
        List<String> missingPermissions = new ArrayList<>();
        for (int i = 0; i < permissions.length; i++) {
            if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                missingPermissions.add(permissions[i]);
            }/*from  w ww  .j  av  a  2 s.  c  om*/
        }
        if (!missingPermissions.isEmpty()) {
            Log.w(TAG, "Permissions not granted: " + missingPermissions.toString());
        }
        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancel(Constants.PERMISSION_MISSING, Constants.PERMISSION_MISSING_NOTIFICATION_ID);
    }
}

From source file:org.totschnig.myexpenses.activity.ProtectedFragmentActivity.java

protected boolean calendarPermissionPermanentlyDeclined() {
    String permission = Manifest.permission.WRITE_CALENDAR;
    return PrefKey.CALENDAR_PERMISSION_REQUESTED.getBoolean(false)
            && (ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_DENIED)
            && !ActivityCompat.shouldShowRequestPermissionRationale(this, permission);
}

From source file:plugin.google.maps.CordovaGoogleMaps.java

public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults)
        throws JSONException {
    PluginResult result;/*from   w w w  . j  a  v  a2s.c o  m*/
    for (int r : grantResults) {
        if (r == PackageManager.PERMISSION_DENIED) {
            result = new PluginResult(PluginResult.Status.ERROR, "Geolocation permission request was denied.");
            _saveCallbackContext.sendPluginResult(result);
            return;
        }
    }
    CordovaGoogleMaps.this.getMyLocation(_saveArgs, _saveCallbackContext);
}

From source file:org.awesomeapp.messenger.ui.ConversationDetailActivity.java

void startFilePicker() {

    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);

    if (permissionCheck == PackageManager.PERMISSION_DENIED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            Snackbar.make(mConvoView.getHistoryView(), R.string.grant_perms, Snackbar.LENGTH_LONG).show();
        } else {//from www.  j a  va2  s . c o m

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    MY_PERMISSIONS_REQUEST_FILE);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    } else {

        Intent selectFile = new Intent(Intent.ACTION_GET_CONTENT);
        Intent intentChooser = Intent.createChooser(selectFile, "Select File");

        if (intentChooser != null)
            startActivityForResult(Intent.createChooser(selectFile, "Select File"), REQUEST_SEND_FILE);
    }
}

From source file:io.jawg.osmcontributor.ui.activities.PhotoActivity.java

/**
 * This method must be called if the android version is 6.0 or higher.
 * Check if the app has ACCESS_LOCATION (COARSE and FINE) and WRITE_EXTERNAL_STORAGE.
 * If the app doesn't have both permission, a request is prompted to the user.
 * For more informations about permission in Android 6.0, please refer to
 * https://developer.android.com/training/permissions/requesting.html?hl=Fr#explain
 *///  w  w w  . ja  v  a  2  s  .c o m
private void requestPermissionIfNeeded() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // Check if permission are enable by the user. Dangerous permissions requested are :
        int hasEnabledCameraPerm = checkSelfPermission(Manifest.permission.CAMERA);

        // If the user have already allow permission, launch map activity, else, ask the user to allow permission
        if (hasEnabledCameraPerm == PackageManager.PERMISSION_DENIED) {
            requestPermissions(new String[] { Manifest.permission.CAMERA }, ALLOW_CAMERA_PERMISSION);
        } else {
            takePicture();
        }
    }
}

From source file:fr.steren.climbtracker.ClimbTrackerActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case PERMISSION_UPFRONT_REQUEST: {
        // first check if we can login
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) {

            // if we can, check if we can see the location, if not, display a message.
            for (int i = 0; i < grantResults.length; i++) {
                if (permissions[i].equals(Manifest.permission.ACCESS_COARSE_LOCATION)
                        && grantResults[i] == PackageManager.PERMISSION_DENIED) {
                    // no problem, just say we are not going to store location
                    final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(
                            R.id.mainLayout);
                    Snackbar.make(coordinatorLayout, R.string.location_permission_denied, Snackbar.LENGTH_LONG)
                            .show();/*  ww w . ja  va  2s .  com*/
                }
            }
            mGoogleAuthApiClient.connect();
        } else {
            // We need this permission to log in, explain and ask again
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.mainLayout);
            Snackbar.make(coordinatorLayout, R.string.account_permission_denied, Snackbar.LENGTH_INDEFINITE)
                    .setAction(android.R.string.ok, new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            // Request the permission again.
                            ActivityCompat.requestPermissions(ClimbTrackerActivity.this,
                                    new String[] { Manifest.permission.GET_ACCOUNTS },
                                    PERMISSION_UPFRONT_REQUEST);
                        }
                    }).show();
        }
    }

    }
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyFragment.java

private void initLinkedContactLoader(long masterKeyId, boolean isSecret) {
    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_DENIED) {
        Log.w(Constants.TAG, "loading linked system contact not possible READ_CONTACTS permission denied!");
        hideLinkedSystemContact();/* w  w w.  ja  va2  s.c o  m*/
        return;
    }

    Bundle linkedContactData = new Bundle();
    linkedContactData.putLong(LOADER_EXTRA_LINKED_CONTACT_MASTER_KEY_ID, masterKeyId);
    linkedContactData.putBoolean(LOADER_EXTRA_LINKED_CONTACT_IS_SECRET, isSecret);

    // initialises loader for contact query so we can listen to any updates
    getLoaderManager().initLoader(LOADER_ID_LINKED_CONTACT, linkedContactData, this);
}

From source file:com.example.android.recyclingbanks.MainActivity.java

/**
 * Uses the logging framework to display the output of the fetch
 * operation in the log fragment./*from www .  j  a  v a 2 s  .  c  om*/
 */
@Override
public void onLoadFinished(android.content.Loader<Boolean> loader, Boolean noMarkers) {
    Log.i("onLoadFinished", "all json processed");
    mProgressBar.setVisibility(ProgressBar.GONE);
    mSpinnerLayout.setVisibility(ProgressBar.GONE);

    if (noMarkers == true) {// || globalBanksList.isEmpty()) {
        // we only assign text here after first load completed to prevent it
        // flashing up while quakes load and misleading user.
        mEmptyView.setVisibility(View.VISIBLE);
        mEmptyView.setText(R.string.no_banks_downloaded_text);
        return;
    }
    // Update the information displayed to the user.

    // check we have permissions to progress
    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
    if (permissionCheck == PackageManager.PERMISSION_DENIED) {
        ActivityCompat.requestPermissions(this,
                new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION },
                MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
    }
    setupMap();

}