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.netease.hearttouch.htimagepicker.core.util.permission.PermissionsActivity.java

private boolean hasAllPermissionsGranted(@NonNull int[] grantResults) {
    for (int grantResult : grantResults) {
        if (grantResult == PackageManager.PERMISSION_DENIED) {
            return false;
        }/*  w w  w. j a  va2  s .  com*/
    }
    return true;
}

From source file:it.flaviomascetti.posture.PostureCheckFragment.java

@Override
public void onStart() {
    super.onStart();

    button = (Button) getActivity().findViewById(R.id.button_posture_check);

    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
        Log.e(getString(R.string.app_name), getString(R.string.error_write_permission));

        ActivityCompat.requestPermissions(getActivity(),
                new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                MY_PERMISSION_REQUEST_SDCARD_WRITE);
    } else // if the permission is granted the button has to be enabled
        button.setEnabled(true);//  w w w.  j  av a2 s  .  c o m

    button.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // Close the keyboard
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);

            inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            // Retrieve the chest height from the editText
            EditText et = (EditText) getActivity().findViewById(R.id.edit_text_height);
            Integer height = Integer.parseInt(et.getText().toString());

            if (height >= 1000 && height <= 2000) {
                chestHeight = height;

                et.setEnabled(false);

                // Check SdCard write permission
                Calendar c = Calendar.getInstance();
                String name = String.valueOf(c.get(Calendar.YEAR)) + "-"
                        + String.valueOf(c.get(Calendar.MONTH) + 1) + "-"
                        + String.valueOf(c.get(Calendar.DAY_OF_MONTH)) + "-"
                        + String.valueOf(c.get(Calendar.HOUR)) + "-" + String.valueOf(c.get(Calendar.MINUTE))
                        + "-" + String.valueOf(c.get(Calendar.SECOND));

                // Create the results file
                file = createFile(folder, name + ".csv");

                // Showing the start snackbar
                Snackbar.make(getActivity().findViewById(R.id.fragment_posture_test), R.string.snack_begin_test,
                        Snackbar.LENGTH_LONG).show();

                // Opening the output stream on the file
                try {
                    bW = new BufferedWriter(new FileWriter(file, true));
                    bW.write("x\t" + //
                    "y\t" + // Acceleration force
                    "z\t" + //
                    "x (mm)\t" + // Conversion of acceleration
                    "z (mm)\t" + // force to mm
                    "dCoP\t" + // Euclidean distance from actualCoP to previous CoP
                    "lengthCoPPath"); // Summation of euclidean dist
                } catch (IOException e) {
                    e.printStackTrace();
                }

                testInProgress = false;

                // Delayed start of function testStart
                Handler handler = new Handler();
                handler.postDelayed(testStart, 7000); // 7000 ms = 7 sec*

                // Make the Begin Button unclickable
                button.setEnabled(false);
            } else {
                // Showing the error snackbar
                Snackbar.make(getActivity().findViewById(R.id.fragment_posture_test),
                        R.string.snack_error_height, Snackbar.LENGTH_LONG).show();
            }

        }
    });
}

From source file:vee.vee.string.downloader.StringDownloader.java

/**
 * @see android.os.AsyncTask#doInBackground(java.lang.Object[])
 *//*from  ww w.j ava 2 s  .  com*/
@Override
protected String doInBackground(String... params) {
    if (activity
            .checkCallingOrSelfPermission(Manifest.permission.INTERNET) == PackageManager.PERMISSION_DENIED) {
        mSetterGetter.setDownloadStatus(false);
        publishProgress(1000);
        Log.wtf(tag, StringDownloaderSnippets.noInternetPermission);
        return null;
    }

    if (debug) {
        Log.w(tag, "doInBackground");
        Log.w(tag, "Number of URL(s) :<>: " + params.length);
    }
    String url;

    for (int i = 0; i < params.length; i++) {

        if (debug) {
            Log.v(tag, "Executing");
        }

        url = params[i];

        publishProgress(1);
        if (!dialog.isShowing()) {

            try {
                dialog = new ProgressDialog(activity);
                dialog.setCancelable(false);
                dialog.setCanceledOnTouchOutside(false);
                dialog.show();
            } catch (final Exception e) {
                if (debug) {
                    Log.wtf(tag, "Dialog Exception" + e.getMessage());
                }
                continue;
            }

        }

        result = null;
        try {

            url = new URL(url).toURI().toString();

            if (debug) {
                Log.w(tag, "Executing URL :<>: " + (i + 1));
                Log.v(tag, url);
            }

            httpGet = new HttpGet(url);

            response = httpClient.execute(httpGet, mCookieJar.getLocalContext());

            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK && response.getEntity() != null) {

                publishProgress(2);

                final HttpEntity httpEntity = response.getEntity();

                result = EntityUtils.toString(httpEntity);

                // Do NOT UPDATE UI IN THREAD, Move this to PostExe
                // strgDwnLsnr.stringDownloadedSuccessfully(result);

                if (debug) {
                    Log.i(tag, "URL > " + (i + 1) + " > Downloaded Successfully");
                }
                mSetterGetter.setDownloadStatus(true);

                if (mCookieJar.getCookieStore() != null) {
                    mCookieJar.setCookieStore(mCookieJar.getCookieStore());
                }
                if (mCookieJar.getLocalContext() != null) {
                    mCookieJar.setLocalContext(mCookieJar.getLocalContext());
                }

                if (result != null) {
                    strgDwnLsnr.stringDownloadedSuccessfully(result, url, i, mCookieJar.getCookieStore());
                } else {

                    /* There is highly NO chance of coming here */

                    reasonForFailure = StringDownloaderSnippets.serverScrewed;
                    strgDwnLsnr.errorInServerSide(response.getStatusLine().getStatusCode(),
                            getStatusEquivalent(response.getStatusLine().getStatusCode()), url, i,
                            mCookieJar.getCookieStore());
                }

            } else {

                strgDwnLsnr.errorInServerSide(response.getStatusLine().getStatusCode(),
                        getStatusEquivalent(response.getStatusLine().getStatusCode()), url, i,
                        mCookieJar.getCookieStore());
                result = null;
                mSetterGetter.setDownloadStatus(false);
                publishProgress(500);
                // Do NOT UPDATE UI IN THREAD, Move this to PostExe
                // strgDwnLsnr.dataDownloadFailed();
            }
        } catch (final Exception e) {

            result = null;
            mSetterGetter.setDownloadStatus(false);
            publishProgress(1000);
            reasonForFailure = e.getMessage();
            strgDwnLsnr.stringFetchingFailed(reasonForFailure, url, i, mCookieJar.getCookieStore());
            if (debug) {
                Log.wtf(tag, reasonForFailure);
            }

        }

    }

    return result;
}

From source file:moe.yukinoneko.gcomic.module.splash.SplashActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    if (requestCode == REQUEST_CODE_ASK_PERMISSIONS) {
        if (grantResults.length > 0) {
            boolean granted = true;
            for (int result : grantResults) {
                if (result == PackageManager.PERMISSION_DENIED) {
                    showPermissionDeniedSnackbar();
                    granted = false;//from  w  w  w.java2  s  .co m
                    break;
                }
            }

            if (granted) {
                toMainActivity();
            }
        } else {
            showPermissionDeniedSnackbar();
        }
    }
}

From source file:com.gelakinetic.inboxwidget.InboxCheckerAppWidgetConfigure.java

/**
 * This is called after permissions were either granted or denied. If permissions were denied,
 * close the activity. If permissions were granted, get a list of accounts
 *
 * @param requestCode  The request code passed in requestPermissions(String[], int).
 * @param permissions  The requested permissions. Never null.
 * @param grantResults The grant results for the corresponding permissions which is either
 *                     PERMISSION_GRANTED or PERMISSION_DENIED. Never null.
 *///w  ww  .  j  a va 2s .  c  om
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    /* Check if the requested permissions were granted */
    for (int grantResult : grantResults) {
        if (grantResult == PackageManager.PERMISSION_DENIED) {
            /* Something was denied, pop a toast and finish */
            Toast.makeText(this, R.string.required_permissions, Toast.LENGTH_LONG).show();
            this.finish();
            return;
        }
    }

    /* All permissions granted, continue */
    getAccounts();
}

From source file:permissionhelper.PermissionHelper.java

/**
 * Callback for the result from requesting permissions. This method
 * is invoked for every call on {@link #requestPermission(Activity, String, String)}.
 *
 * @param obj/*  w w w. java  2  s  .c o  m*/
 * @param permissions
 * @param grantResults
 */
public void onRequestPermissionsResult(Object obj, String[] permissions, int[] grantResults) {
    /*if (isGranted(grantResults)) {
    if(permissions[0] !=null)
    invokeGrantedMethod(obj, permissions[0]);
    } else {
    if(permissions[0] !=null)
    invokeDeniedMethod(obj, permissions[0]);
    }*/
    if (permissions != null && verifyPermissions(grantResults)) {
        for (int i = 0; i < permissions.length; i++) {
            if (grantResults[i] == PackageManager.PERMISSION_GRANTED)
                invokeGrantedMethod(obj, permissions[i]);
            else if (grantResults[i] == PackageManager.PERMISSION_DENIED)
                invokeDeniedMethod(obj, permissions[i]);
        }
    }
}

From source file:de.madvertise.android.sdk.MadView.java

/**
 * Constructor/*from w  w  w . j  av  a 2s.com*/
 * 
 * @param context
 * @param attrs
 */
public MadView(Context context, AttributeSet attrs) {
    super(context, attrs);

    MadUtil.logMessage(null, Log.DEBUG, "** Constructor for mad view called **");
    setVisibility(INVISIBLE);

    if (context.checkCallingOrSelfPermission(
            android.Manifest.permission.INTERNET) == PackageManager.PERMISSION_DENIED) {

        MadUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** ");
        MadUtil.logMessage(null, Log.DEBUG, " *** Missing internet permissions! *** ");
        MadUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** ");
        throw new IllegalArgumentException();
    }

    initParameters(attrs);

    Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    MadUtil.logMessage(null, Log.DEBUG,
            "Display values: Width = " + display.getWidth() + " ; Height = " + display.getHeight());

    setGravity(Gravity.CENTER);

    initialBackground = this.getBackground();
    Rect r = new Rect(0, 0, display.getWidth(), display.getHeight());
    textBannerBackground = generateBackgroundDrawable(r, backgroundColor, 0xffffff);

    setClickable(true);
    setFocusable(true);
    setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
}

From source file:org.deviceconnect.android.deviceplugin.hvcc2w.setting.fragment.HVCC2WPairingFragment.java

/** Check Permission. */
private void checkPermission() {
    // WiFi scan requires location permissions.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP + 1) {
        if (PermissionChecker.checkSelfPermission(getContext(),
                Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
                && PermissionChecker.checkSelfPermission(getContext(),
                        Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            searchWifi();//ww w  . ja v  a2s .c  o  m
        } else {
            PermissionRequestActivity.requestPermissions(getContext(),
                    new String[] { Manifest.permission.ACCESS_COARSE_LOCATION,
                            Manifest.permission.ACCESS_FINE_LOCATION },
                    new ResultReceiver(new Handler(Looper.getMainLooper())) {
                        @Override
                        protected void onReceiveResult(final int resultCode, final Bundle resultData) {
                            String[] retPermissions = resultData.getStringArray("EXTRA_PERMISSIONS");
                            int[] retGrantResults = resultData.getIntArray("EXTRA_GRANT_RESULTS");
                            if (retPermissions == null || retGrantResults == null) {
                                HVCC2WDialogFragment.showAlert(getActivity(), getString(R.string.hw_name),
                                        "WiFi scan aborted.", null);
                                return;
                            }
                            for (int i = 0; i < retPermissions.length; ++i) {
                                if (retGrantResults[i] == PackageManager.PERMISSION_DENIED) {
                                    HVCC2WDialogFragment.showAlert(getActivity(), getString(R.string.hw_name),
                                            "WiFi scan aborted.", null);
                                    return;
                                }
                            }
                            searchWifi();
                        }
                    });
        }
    }
}

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

private boolean checkPermissions() {
    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_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(mStickerPager, R.string.grant_perms, Snackbar.LENGTH_LONG).show();
        } else {/*from w  ww .  ja v  a  2s  .  co  m*/

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

            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_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.
        }

        return false;

    } else {

        return true;
    }
}

From source file:com.hplasplas.cam_capture.activitys.CamCapture.java

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

    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == PERMISSION_REQUEST_CODE && grantResults.length == 1
            && grantResults[0] == PackageManager.PERMISSION_DENIED) {
        ShowNoPermissionMessage();//from   w  ww  .  j  a v a2s  . c  o  m
    }
}