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:com.jaspersoft.android.jaspermobile.activities.save.fragment.SaveItemFragment.java

@OptionsItem
final void saveAction() {
    if (canMakeSmores()) {
        boolean permissionDenied = (ContextCompat.checkSelfPermission(getActivity(),
                WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED);
        if (permissionDenied) {
            requestPermissions(new String[] { WRITE_EXTERNAL_STORAGE },
                    PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
            return;
        }// w w  w  .  j  a  v  a  2s  .  c  o  m
    }
    performSaveAction();
}

From source file:com.justinbull.ichnaeachecker.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from w  ww.  ja va  2 s. com
    setCellInfo();
    mCellListView = (ListView) findViewById(R.id.cellListView);
    mCellListView.setAdapter(mCellListAdapter);
    mCellListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    mCellListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            GeneralCellInfo cell = (GeneralCellInfo) parent.getItemAtPosition(position);
            if (!cell.isFullyKnown()) {
                Snackbar snack = Snackbar.make(view, "Not enough information known about selected cell",
                        Snackbar.LENGTH_SHORT);
                snack.getView()
                        .setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorError));
                snack.show();
                return;
            }
            mSelectedCell = cell;
            view.setSelected(true);
            Snackbar.make(view, "Selected " + mSelectedCell.getCellType() + " Cell "
                    + mSelectedCell.getFriendlyCellIdentity(), Snackbar.LENGTH_SHORT).show();
        }
    });

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    assert fab != null;
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            if (ContextCompat.checkSelfPermission(MainActivity.this,
                    android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) {
                setCellInfo();
            }
            if (mSelectedCell == null) {
                Toast.makeText(MainActivity.this, "Choose a cell to check", Toast.LENGTH_SHORT).show();
                return;
            }
            final Snackbar snack = Snackbar.make(view, "Checking Mozilla Location Services database...",
                    Snackbar.LENGTH_INDEFINITE);
            snack.show();
            try {
                final RequestHandle handler = getIchnaeaLookup(snack);
                assert handler != null;
                snack.setAction("CANCEL", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        snack.setText("Cancelling lookup request...");
                        if (!handler.isFinished()) {
                            handler.cancel(true);
                        } else {
                            snack.setText("Request already finished!");
                            snack.setDuration(Snackbar.LENGTH_LONG);
                            snack.show();
                        }
                    }
                }).show();
            } catch (IllegalArgumentException e) {
                Log.w(TAG, "onClick: ", e);
                snack.setDuration(Snackbar.LENGTH_SHORT);
                snack.setText("Not enough information known about selected cell");
                snack.show();
            }
        }
    });
}

From source file:com.android.projectz.teamrocket.thebusapp.IntroApp.java

/**
 * controllo per i permessi che l'applicazione deve avere
 * per funzionare al meglio// w  w w  .  ja va2 s  .c  o  m
 */
private boolean permission() {
    boolean permissionGrant = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        for (int i = 0; i < permissions.length; i++) {
            if (getApplicationContext()
                    .checkCallingOrSelfPermission(permissions[i]) == PackageManager.PERMISSION_DENIED) {
                permissionGrant = false;
            }
        }
    }
    return permissionGrant;
}

From source file:org.dkf.jmule.util.DangerousPermissionsChecker.java

private boolean noExternalStorageAccess() {
    if (!Ref.alive(activityRef)) {
        return true;
    }//from  w w w.  j a  v a 2 s . c  o  m
    Activity activity = activityRef.get();
    return ActivityCompat.checkSelfPermission(activity,
            Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED
            || ActivityCompat.checkSelfPermission(activity,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED;
}

From source file:com.google.android.gms.nearby.messages.samples.hellobeacons.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (requestCode != PERMISSIONS_REQUEST_CODE) {
        return;/*  www.j  av a 2s. c o  m*/
    }
    for (int i = 0; i < permissions.length; i++) {
        String permission = permissions[i];
        if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
            if (shouldShowRequestPermissionRationale(permission)) {
                Log.i(TAG, "Permission denied without 'NEVER ASK AGAIN': " + permission);
                showRequestPermissionsSnackbar();
            } else {
                Log.i(TAG, "Permission denied with 'NEVER ASK AGAIN': " + permission);
                showLinkToSettingsSnackbar();
            }
        } else {
            Log.i(TAG, "Permission granted, building GoogleApiClient");
            //buildGoogleApiClient();
        }
    }
}

From source file:com.example.angel.parkpanda.MySplashScreen.java

@TargetApi(Build.VERSION_CODES.M)
private void checkAndRequestPermissions() {

    int permissionCheckSTOR = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    int permissionCheckLOC = checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);

    if ((permissionCheckLOC == PackageManager.PERMISSION_DENIED)
            || (permissionCheckSTOR == PackageManager.PERMISSION_DENIED)) {
        this.requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.ACCESS_FINE_LOCATION }, 130);
    } else if ((permissionCheckSTOR == PackageManager.PERMISSION_GRANTED)
            && (permissionCheckLOC == PackageManager.PERMISSION_GRANTED)) {
        if (checkAlradyLogin() == 1) {
            Intent intent = new Intent(MySplashScreen.this, MainActivity.class);
            finish();/*from   w w w. ja v  a 2s . c o m*/
            startActivity(intent);
        }
    }

}

From source file:com.google.android.gms.nearby.messages.samples.nearbybackgroundbeacons.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (requestCode != PERMISSIONS_REQUEST_CODE) {
        return;/*from ww  w .ja  v  a2 s  . c om*/
    }
    for (int i = 0; i < permissions.length; i++) {
        String permission = permissions[i];
        if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
            // There are states to watch when a user denies permission when presented with
            // the Nearby permission dialog: 1) When the user pressed "Deny", but does not
            // check the "Never ask again" option. In this case, we display a Snackbar which
            // lets the user kick off the permissions flow again. 2) When the user pressed
            // "Deny" and also checked the "Never ask again" option. In this case, the
            // permission dialog will no longer be presented to the user. The user may still
            // want to authorize location and use the app, and we present a Snackbar that
            // directs them to go to Settings where they can grant the location permission.
            if (shouldShowRequestPermissionRationale(permission)) {
                Log.i(TAG, "Permission denied without 'NEVER ASK AGAIN': " + permission);
                showRequestPermissionsSnackbar();
            } else {
                Log.i(TAG, "Permission denied with 'NEVER ASK AGAIN': " + permission);
                showLinkToSettingsSnackbar();
            }
        } else {
            Log.i(TAG, "Permission granted, building GoogleApiClient");
            buildGoogleApiClient();
        }
    }
}

From source file:com.android.messaging.util.OsUtil.java

/**
 * Check if the app has the specified permission. If it does not, the app needs to use
 * {@link android.app.Activity#requestPermission}. Note that if it
 * returns true, it cannot return false in the same process as the OS kills the process when
 * any permission is revoked./*from   w ww.j  a  v a2 s .co  m*/
 * @param permission A permission from {@link android.Manifest.permission}
 */
public static boolean hasPermission(final String permission) {
    if (OsUtil.isAtLeastM()) {
        // It is safe to cache the PERMISSION_GRANTED result as the process gets killed if the
        // user revokes the permission setting. However, PERMISSION_DENIED should not be
        // cached as the process does not get killed if the user enables the permission setting.
        if (!sPermissions.containsKey(permission)
                || sPermissions.get(permission) == PackageManager.PERMISSION_DENIED) {
            final Context context = Factory.get().getApplicationContext();
            final int permissionState = context.checkSelfPermission(permission);
            sPermissions.put(permission, permissionState);
        }
        return sPermissions.get(permission) == PackageManager.PERMISSION_GRANTED;
    } else {
        return true;
    }
}

From source file:org.samcrow.ridgesurvey.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(getString(R.string.map));//from   ww  w. j a  v a 2  s. c o  m

    // Check location permission
    final int permission = ActivityCompat.checkSelfPermission(this, LOCATION_PERMISSION);
    if (permission == PackageManager.PERMISSION_DENIED) {
        ActivityCompat.requestPermissions(this, new String[] { LOCATION_PERMISSION }, LOCATION_PERMISSION_CODE);
    }

    // Set up map graphics
    if (AndroidGraphicFactory.INSTANCE == null || new View(this).isInEditMode()) {
        AndroidGraphicFactory.createInstance(getApplication());
    }

    setContentView(R.layout.activity_main);

    mSelectionManager = new SelectionManager();

    mLocationFinder = new LocationFinder(this);

    // Set up upload status tracker
    mUploadStatusTracker = new UploadStatusTracker(this);
    mUploadStatusTracker.addListener((UploadStatusListener) findViewById(R.id.upload_status_bar));

    final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
    final IntentFilter filter = new IntentFilter();
    filter.addAction(UploadStatusTracker.ACTION_OBSERVATION_MADE);
    filter.addAction(UploadStatusTracker.ACTION_UPLOAD_STARTED);
    filter.addAction(UploadStatusTracker.ACTION_UPLOAD_SUCCESS);
    filter.addAction(UploadStatusTracker.ACTION_UPLOAD_FAILED);
    manager.registerReceiver(mUploadStatusTracker, filter);

    // Check for upload/delete every minute
    final IntentFilter tickFilter = new IntentFilter();
    tickFilter.addAction(Intent.ACTION_TIME_TICK);
    registerReceiver(new NetworkBroadcastReceiver(), tickFilter);

    // Set up compass
    mCompass = (Compass) findViewById(R.id.compass);
    mHeadingCalculator = new HeadingCalculator(this);
    if (mHeadingCalculator.isAvailable()) {
        Log.d(TAG, "Heading available");
        mHeadingCalculator.setHeadingListener(new HeadingListener() {
            @Override
            public void headingUpdated(double heading) {
                mCompass.setHeading(heading);
            }
        });
    } else {
        Log.d(TAG, "Heading not available");
        mCompass.setVisibility(View.INVISIBLE);
    }

    mPreferences = getSharedPreferences(TAG, MODE_PRIVATE);
    mPreferencesFacade = new AndroidPreferences(mPreferences);
    try {
        setUpMap();
    } catch (IOException e) {
        new AlertDialog.Builder(this).setTitle(R.string.failed_to_load_map).setMessage(e.getLocalizedMessage())
                .show();
        Log.e(TAG, "Failed to set up map", e);
    }

    startUpload();
}

From source file:com.frostwire.android.gui.util.DangerousPermissionsChecker.java

private boolean noExternalStorageAccess() {
    if (!Ref.alive(activityRef)) {
        return true;
    }//from   w  w w  . j a  v a  2s  .  c  o  m
    Activity activity = activityRef.get();
    return ContextCompat.checkSelfPermission(activity,
            Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED
            || ContextCompat.checkSelfPermission(activity,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED;
}