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.amaze.filemanager.activities.MainActivity.java

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

    if (requestCode == 77) {
        if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            updateDrawer();//from w  w w  . j a v a2  s .c o  m
            TabFragment tabFragment = getFragment();
            boolean b = Sp.getBoolean("needtosethome", true);
            //reset home and current paths according to new storages
            if (b) {
                tabHandler.clear();
                if (storage_count > 1)
                    tabHandler.addTab(new Tab(1, "", ((EntryItem) DataUtils.list.get(1)).getPath(), "/"));
                else
                    tabHandler.addTab(new Tab(1, "", "/", "/"));
                if (!DataUtils.list.get(0).isSection()) {
                    String pa = ((EntryItem) DataUtils.list.get(0)).getPath();
                    tabHandler.addTab(new Tab(2, "", pa, pa));
                } else
                    tabHandler.addTab(new Tab(2, "", ((EntryItem) DataUtils.list.get(1)).getPath(), "/"));
                if (tabFragment != null) {
                    Fragment main = tabFragment.getTab(0);
                    if (main != null)
                        ((Main) main).updateTabWithDb(tabHandler.findTab(1));
                    Fragment main1 = tabFragment.getTab(1);
                    if (main1 != null)
                        ((Main) main1).updateTabWithDb(tabHandler.findTab(2));
                }
                Sp.edit().putBoolean("needtosethome", false).commit();
            } else {
                //just refresh list
                if (tabFragment != null) {
                    Fragment main = tabFragment.getTab(0);
                    if (main != null)
                        ((Main) main).updateList();
                    Fragment main1 = tabFragment.getTab(1);
                    if (main1 != null)
                        ((Main) main1).updateList();
                }
            }
        } else {
            Toast.makeText(this, R.string.grantfailed, Toast.LENGTH_SHORT).show();
            requestStoragePermission();
        }

    }
}

From source file:com.amaze.filemanager.activities.MainActivity.java

public boolean checkStoragePermission() {

    // Verify that all required contact permissions have been granted.
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
        return true;
    }/*  ww  w  .j  ava2 s . c om*/
    return false;
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

private void openFilePicker() {

    // Check Dangerous permissions (Android 6.0+, API 23+)
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            genericOkDialog(R.string.error_permission2, new DialogInterface.OnClickListener() {
                @Override//from  www . j ava 2 s .c  om
                public void onClick(DialogInterface dialog, int which) {
                    ActivityCompat.requestPermissions(MainActivity.this,
                            new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE,
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE },
                            MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
                }
            });

        } else {

            // No explanation needed, request the permission.
            ActivityCompat.requestPermissions(this,
                    new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE,
                            Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);

        }

    } else {

        // Permissions granted, open file picker
        Intent intent = new Intent(getApplicationContext(), FilePickerActivity.class);
        intent.putExtra(FilePickerActivity.ARG_FILE_FILTER, Pattern.compile(".*\\.torrent"));
        //            startActivityForResult(INTENT, RESULT_CODE);
        startActivityForResult(intent, ADDFILE_CODE);

    }

}

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

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case Util.REQUEST_ACCESS_FINE_LOCATION: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.

            initGeoposition();/*from w  w w. j  ava 2s.c o m*/

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.

            Log.w("LectorActivity", "No hay permisos de ACCESS_FINE_LOCATION");
        }
        break;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

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

    if (requestCode == 77) {
        if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            refreshDrawer();// w ww. ja v a  2 s .  c  o  m
            TabFragment tabFragment = getFragment();
            boolean b = sharedPref.getBoolean("needtosethome", true);
            //reset home and current paths according to new storages
            if (b) {
                tabHandler.clear();
                if (storage_count > 1)
                    tabHandler.addTab(new Tab(1, "", ((EntryItem) dataUtils.getList().get(1)).getPath(), "/"));
                else
                    tabHandler.addTab(new Tab(1, "", "/", "/"));
                if (!dataUtils.getList().get(0).isSection()) {
                    String pa = ((EntryItem) dataUtils.getList().get(0)).getPath();
                    tabHandler.addTab(new Tab(2, "", pa, pa));
                } else
                    tabHandler.addTab(new Tab(2, "", ((EntryItem) dataUtils.getList().get(1)).getPath(), "/"));
                if (tabFragment != null) {
                    Fragment main = tabFragment.getTab(0);
                    if (main != null)
                        ((MainFragment) main).updateTabWithDb(tabHandler.findTab(1));
                    Fragment main1 = tabFragment.getTab(1);
                    if (main1 != null)
                        ((MainFragment) main1).updateTabWithDb(tabHandler.findTab(2));
                }
                sharedPref.edit().putBoolean("needtosethome", false).commit();
            } else {
                //just refresh list
                if (tabFragment != null) {
                    Fragment main = tabFragment.getTab(0);
                    if (main != null)
                        ((MainFragment) main).updateList();
                    Fragment main1 = tabFragment.getTab(1);
                    if (main1 != null)
                        ((MainFragment) main1).updateList();
                }
            }
        } else {
            Toast.makeText(this, R.string.grantfailed, Toast.LENGTH_SHORT).show();
            requestStoragePermission();
        }
    }
}

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

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case Util.REQUEST_ACCESS_FINE_LOCATION: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.

            initGeoposition();/*w ww.  j av  a2 s .  c o  m*/

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.

            Log.w("CatastroActivity", "No hay permisos de ACCESS_FINE_LOCATION");
        }
        break;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}

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

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case Util.REQUEST_ACCESS_FINE_LOCATION: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.

            initGeoposition();/*from w  w w . j a  va 2s .c  om*/

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.
        }
        break;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}

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

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case Util.REQUEST_ACCESS_FINE_LOCATION: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.

            initGeoposition();/* w  w w .  j  ava2s.c  o m*/

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.

        }
        break;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}

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

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case Util.REQUEST_ACCESS_FINE_LOCATION: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.

            initGeoposition();/*ww  w. jav a 2  s .com*/

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.

            Toast.makeText(InspActivity.this, "No puede utilizar GPS, contacte soporte", Toast.LENGTH_LONG)
                    .show();
        }
        break;
    }
    case Util.REQUEST_READ_EXTERNAL_STORAGE: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.
            Toast.makeText(InspActivity.this, "Ya puede utilizar archivos, presione nuevamente",
                    Toast.LENGTH_LONG).show();

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.

            Toast.makeText(InspActivity.this, "No puede utilizar archivos, contacte soporte", Toast.LENGTH_LONG)
                    .show();
        }
        break;
    }
    case Util.REQUEST_CAMERA: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.
            Toast.makeText(InspActivity.this, "Ya puede utilizar camara, presione nuevamente",
                    Toast.LENGTH_LONG).show();

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.

            Toast.makeText(InspActivity.this, "No puede utilizar camara, contacte soporte", Toast.LENGTH_LONG)
                    .show();
        }
        break;
    }
    case Util.REQUEST_WRITE_EXTERNAL_STORAGE: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.
            Toast.makeText(InspActivity.this, "Ya puede copiar archivos, presione nuevamente",
                    Toast.LENGTH_LONG).show();

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.

            Toast.makeText(InspActivity.this, "No puede copiar archivos, contacte soporte", Toast.LENGTH_LONG)
                    .show();
        }
        break;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}