Example usage for android.app Activity checkSelfPermission

List of usage examples for android.app Activity checkSelfPermission

Introduction

In this page you can find the example usage for android.app Activity checkSelfPermission.

Prototype

@Override
    public int checkSelfPermission(String permission) 

Source Link

Usage

From source file:Main.java

@TargetApi(value = Build.VERSION_CODES.M)
public static boolean hasNeverAskAgainPermission(Activity activity, List<String> permission) {
    for (String value : permission) {
        if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED
                && !activity.shouldShowRequestPermissionRationale(value)) {
            return true;
        }//w w w.  ja  v a2 s  .  c o m
    }

    return false;
}

From source file:Main.java

@TargetApi(value = Build.VERSION_CODES.M)
public static List<String> findDeniedPermissions(Activity activity, String... permission) {
    List<String> denyPermissions = new ArrayList<>();
    for (String value : permission) {
        if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) {
            denyPermissions.add(value);//from w  w  w .j a  va2 s  .  c o m
        }
    }
    return denyPermissions;
}

From source file:pl.lawiusz.lockscreenvisualizerxposed.SettingsActivity.java

@TargetApi(Build.VERSION_CODES.M)
private static boolean isPermRecordGranted(Activity activity) {
    return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || activity
            .checkSelfPermission(Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
}

From source file:pl.lawiusz.lockscreenvisualizerxposed.SettingsActivity.java

@TargetApi(Build.VERSION_CODES.M)
private static boolean isPermModAudioGranted(Activity activity) {
    return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || activity.checkSelfPermission(
            Manifest.permission.MODIFY_AUDIO_SETTINGS) == PackageManager.PERMISSION_GRANTED;
}

From source file:de.baumann.browser.helper.helper_main.java

public static void grantPermissionsLoc(final Activity from) {

    final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);

    if (android.os.Build.VERSION.SDK_INT >= 23) {

        if (sharedPref.getBoolean("perm_notShow", false)) {
            int hasACCESS_FINE_LOCATION = from.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
            if (hasACCESS_FINE_LOCATION != PackageManager.PERMISSION_GRANTED) {
                if (!from.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
                    new AlertDialog.Builder(from).setTitle(R.string.app_permissions_title)
                            .setMessage(helper_main.textSpannable(from.getString(R.string.app_permissions)))
                            .setNeutralButton(R.string.toast_notAgain, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                    sharedPref.edit().putBoolean("perm_notShow", false).apply();
                                }//from   ww w  .  ja va 2  s . c om
                            }).setPositiveButton(from.getString(R.string.toast_yes),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            if (android.os.Build.VERSION.SDK_INT >= 23)
                                                from.requestPermissions(
                                                        new String[] {
                                                                Manifest.permission.ACCESS_FINE_LOCATION },
                                                        REQUEST_CODE_ASK_PERMISSIONS_1);
                                        }
                                    })
                            .setNegativeButton(from.getString(R.string.toast_cancel), null).show();
                    return;
                }
                from.requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                        REQUEST_CODE_ASK_PERMISSIONS_1);
            }
        }
    }
}

From source file:de.baumann.browser.helper.helper_main.java

public static void grantPermissionsStorage(final Activity from) {

    final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);

    if (android.os.Build.VERSION.SDK_INT >= 23) {
        if (sharedPref.getBoolean("perm_notShow", false)) {
            int hasWRITE_EXTERNAL_STORAGE = from
                    .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                if (!from.shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

                    new AlertDialog.Builder(from).setTitle(R.string.app_permissions_title)
                            .setMessage(helper_main.textSpannable(from.getString(R.string.app_permissions)))
                            .setNeutralButton(R.string.toast_notAgain, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                    sharedPref.edit().putBoolean("perm_notShow", false).apply();
                                }/*from  w  w w. j a  v  a 2  s .  c  om*/
                            }).setPositiveButton(from.getString(R.string.toast_yes),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            if (android.os.Build.VERSION.SDK_INT >= 23)
                                                from.requestPermissions(
                                                        new String[] {
                                                                Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                        REQUEST_CODE_ASK_PERMISSIONS);
                                        }
                                    })
                            .setNegativeButton(from.getString(R.string.toast_cancel), null).show();
                    return;
                }
                from.requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                        REQUEST_CODE_ASK_PERMISSIONS);
            }
        }
    }
}

From source file:com.oodles.smslistener.SmsListenerModule.java

@Kroll.method
private boolean hasSMSReceivePermission() {
    if (Build.VERSION.SDK_INT < 23) {
        return true;
    }// www. j  a  va 2s  .c om
    Activity currentActivity = TiApplication.getInstance().getCurrentActivity();
    if (currentActivity
            .checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED) {
        return true;
    }
    return false;
}

From source file:ti.modules.titanium.android.AndroidModule.java

@Kroll.method
public boolean hasPermission(String permission) {
    if (Build.VERSION.SDK_INT < 23) {
        return true;
    }/*from  w  w w .ja v  a  2s.  c  om*/
    Activity currentActivity = TiApplication.getInstance().getCurrentActivity();
    if (currentActivity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
        return true;
    }
    return false;
}

From source file:fashiome.android.fragments.MapListFragment.java

private LatLng getLastKnownLocation(boolean isMoveMarker) {
    LocationManager lm = (LocationManager) AppStarter.getAppContext()
            .getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_LOW);
    String provider = lm.getBestProvider(criteria, true);
    if (provider == null) {
        return null;
    }// w  w  w  .jav a 2 s .co  m
    Activity activity = getActivity();
    if (activity == null) {
        return null;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && activity.checkSelfPermission(
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return null;
        }
    }
    Location loc = lm.getLastKnownLocation(provider);
    if (loc != null) {
        LatLng latLng = new LatLng(loc.getLatitude(), loc.getLongitude());
        if (isMoveMarker) {
            moveMarker(latLng);
        }
        return latLng;
    }
    return null;
}

From source file:ti.modules.titanium.android.AndroidModule.java

@Kroll.method
public void requestPermissions(String[] permissions,
        @Kroll.argument(optional = true) KrollFunction permissionCallback) {
    if (Build.VERSION.SDK_INT < 23) {
        return;//ww w .j  av a  2s  . c o m
    }
    Activity currentActivity = TiApplication.getInstance().getCurrentActivity();
    ArrayList<String> filteredPermissions = new ArrayList<String>();
    //filter out granted permissions
    for (int i = 0; i < permissions.length; ++i) {
        String perm = permissions[i];
        if (currentActivity.checkSelfPermission(perm) == PackageManager.PERMISSION_GRANTED) {
            continue;
        }
        filteredPermissions.add(perm);
    }

    if (filteredPermissions.size() == 0) {
        Log.w(TAG, "Permission(s) already granted");
        return;
    }
    TiBaseActivity.registerPermissionRequestCallback(REQUEST_CODE, permissionCallback, getKrollObject());
    currentActivity.requestPermissions(filteredPermissions.toArray(new String[filteredPermissions.size()]),
            REQUEST_CODE);
}