List of usage examples for android.content.pm PackageManager PERMISSION_DENIED
int PERMISSION_DENIED
To view the source code for android.content.pm PackageManager PERMISSION_DENIED.
Click Source Link
From source file:com.codepiex.droidlibx.permission.PermissionRequestor.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { if (listener != null) { boolean allGranted = grantResults.length > 0; for (int result : grantResults) { if (result == PackageManager.PERMISSION_DENIED) { allGranted = false;//from w w w. ja v a 2 s. c o m break; } } if (allGranted) { listener.onPermissionGranted(); } else { listener.onPermissionDenied(); } } }
From source file:com.google.games.bridge.TokenFragment.java
/** * Processes the token requests that are queued up. * First checking that the google api client is connected. * If the error code is not SUCCESS, then all the requests in the queue * are failed using the given error code. * * @param errorCode - if not SUCCESS, all requests are failed using this code. *//*from w w w .ja v a 2 s.c o m*/ private void processRequests(int errorCode) { TokenRequest request = null; if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) { Log.d(TAG, "mGoogleApiClient not created yet..."); if (mGoogleApiClient != null && !mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } return; } if (!pendingTokenRequests.isEmpty()) { if (!permissionResolved()) { return; } else if (mPermissionResult == PackageManager.PERMISSION_DENIED) { errorCode = CommonStatusCodes.AUTH_API_ACCESS_FORBIDDEN; } } Log.d(TAG, "Pending map in processRequests is " + pendingTokenRequests.size()); while (!pendingTokenRequests.isEmpty()) { // check again since we can disconnect in the loop. if (!mGoogleApiClient.isConnected()) { if (mGoogleApiClient.isConnecting()) { Log.w(TAG, "Still connecting.... hold on..."); } else { Log.w(TAG, "Google API Client not connected! calling connect"); mGoogleApiClient.connect(); } return; } try { synchronized (pendingTokenRequests) { if (!pendingTokenRequests.isEmpty()) { request = pendingTokenRequests.remove(0); } } if (request == null) { continue; } if (errorCode == CommonStatusCodes.SUCCESS) { doGetToken(request); } else { request.setResult(errorCode); } } catch (Throwable th) { if (request != null) { Log.e(TAG, "Cannot process request", th); request.setResult(CommonStatusCodes.ERROR); } } } Log.d(TAG, "Done with processRequests!"); }
From source file:net.kenevans.android.bleexplorer.DeviceScanActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case PERMISSION_ACCESS_COARSE_LOCATION: // COARSE_LOCATION if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mAllowScan = true;//from w w w .ja v a 2 s . c o m startScan(); } else if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_DENIED) { mAllowScan = false; } break; } }
From source file:com.hplasplas.cam_capture.activitys.CamCapture.java
private void requestWriteExtStorageIfNeed() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !NEED_PRIVATE_FOLDER && ContextCompat.checkSelfPermission(ThisApplication.getInstance().getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { if (!requestPermissionWithRationale()) { requestWriteExtStorage(PERMISSION_REQUEST_CODE); }//from w ww. ja v a 2 s .c o m } }
From source file:org.hygieiasoft.cordova.uid.UID.java
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { Log.d(TAG, "onRequestPermissionResult: ***"); needRequestPermission = true;/*from w w w. j a va 2 s. co m*/ for (int i = 0; i < permissions.length; i++) { if (permissions[i].equals(Manifest.permission.READ_PHONE_STATE)) { if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { UID.imei = getImei(context); UID.imsi = getImsi(context); UID.iccid = getIccid(context); JSONObject r = new JSONObject(); r.put("UUID", UID.uuid); r.put("IMEI", UID.imei); r.put("IMSI", UID.imsi); r.put("ICCID", UID.iccid); r.put("MAC", UID.mac); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, r); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } else if (grantResults[i] == PackageManager.PERMISSION_DENIED) { Log.w(TAG, "onRequestPermissionResult: permission READ_PHONE_STATE denied"); //it's for execute callback. PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } } } }
From source file:com.hacktj.eshasaini.elert.LocationActivity.java
/** * Runs when a GoogleApiClient object successfully connects. *//* w w w . ja va 2 s . com*/ @Override public void onConnected(Bundle connectionHint) { // Provides a simple way of getting a device's location and is well suited for // applications that do not require a fine-grained location and that do not need location // updates. Gets the best and most recent location currently available, which may be null // in rare cases when a location is not available. int permission = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION); if (permission == PackageManager.PERMISSION_DENIED) { throw new RuntimeException("need permission"); } mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (mLastLocation != null) { mLatitudeText.setText(String.format("%s: %f", mLatitudeLabel, mLastLocation.getLatitude())); mLongitudeText.setText(String.format("%s: %f", mLongitudeLabel, mLastLocation.getLongitude())); } else { Toast.makeText(this, R.string.no_location_detected, Toast.LENGTH_LONG).show(); } }
From source file:de.spiritcroc.syncsettings.Util.java
public static void maybeRequestPermissions(Activity activity, String[] permissions) { ArrayList<String> denied = new ArrayList<>(); for (String permission : permissions) { if (ContextCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_DENIED) { denied.add(permission);/* ww w . jav a 2 s .com*/ } } if (!denied.isEmpty()) { String[] require = denied.toArray(new String[denied.size()]); if (DEBUG) { for (String s : require) { Log.d(LOG_TAG, "Require permission " + s); } } ActivityCompat.requestPermissions(activity, require, 0); } }
From source file:be.ppareit.swiftp.gui.PreferenceFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); Resources resources = getResources(); TwoStatePreference runningPref = findPref("running_switch"); updateRunningState();/*from ww w. j ava 2 s. c om*/ runningPref.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { startServer(); } else { stopServer(); } return true; }); PreferenceScreen prefScreen = findPref("preference_screen"); Preference marketVersionPref = findPref("market_version"); marketVersionPref.setOnPreferenceClickListener(preference -> { // start the market at our application Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse("market://details?id=be.ppareit.swiftp")); try { // this can fail if there is no market installed startActivity(intent); } catch (Exception e) { Cat.e("Failed to launch the market."); e.printStackTrace(); } return false; }); if (!App.isFreeVersion()) { prefScreen.removePreference(marketVersionPref); } updateLoginInfo(); EditTextPreference usernamePref = findPref("username"); usernamePref.setOnPreferenceChangeListener((preference, newValue) -> { String newUsername = (String) newValue; if (preference.getSummary().equals(newUsername)) return false; if (!newUsername.matches("[a-zA-Z0-9]+")) { Toast.makeText(getActivity(), R.string.username_validation_error, Toast.LENGTH_LONG).show(); return false; } stopServer(); return true; }); mPassWordPref = findPref("password"); mPassWordPref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); mAutoconnectListPref = findPref("autoconnect_preference"); mAutoconnectListPref.setOnPopulateListener(pref -> { Cat.d("autoconnect populate listener"); WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); if (configs == null) { Cat.e("Unable to receive wifi configurations, bark at user and bail"); Toast.makeText(getActivity(), R.string.autoconnect_error_enable_wifi_for_access_points, Toast.LENGTH_LONG).show(); return; } CharSequence[] ssids = new CharSequence[configs.size()]; CharSequence[] niceSsids = new CharSequence[configs.size()]; for (int i = 0; i < configs.size(); ++i) { ssids[i] = configs.get(i).SSID; String ssid = configs.get(i).SSID; if (ssid.length() > 2 && ssid.startsWith("\"") && ssid.endsWith("\"")) { ssid = ssid.substring(1, ssid.length() - 1); } niceSsids[i] = ssid; } pref.setEntries(niceSsids); pref.setEntryValues(ssids); }); mAutoconnectListPref.setOnPreferenceClickListener(preference -> { Cat.d("Clicked"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) { if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)) { new AlertDialog.Builder(getContext()).setTitle(R.string.request_coarse_location_dlg_title) .setMessage(R.string.request_coarse_location_dlg_message) .setPositiveButton(android.R.string.ok, (dialog, which) -> { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); }).setOnCancelListener(dialog -> { mAutoconnectListPref.getDialog().cancel(); }).create().show(); } else { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); } } } return false; }); EditTextPreference portnum_pref = findPref("portNum"); portnum_pref.setSummary(sp.getString("portNum", resources.getString(R.string.portnumber_default))); portnum_pref.setOnPreferenceChangeListener((preference, newValue) -> { String newPortnumString = (String) newValue; if (preference.getSummary().equals(newPortnumString)) return false; int portnum = 0; try { portnum = Integer.parseInt(newPortnumString); } catch (Exception e) { Cat.d("Error parsing port number! Moving on..."); } if (portnum <= 0 || 65535 < portnum) { Toast.makeText(getActivity(), R.string.port_validation_error, Toast.LENGTH_LONG).show(); return false; } preference.setSummary(newPortnumString); stopServer(); return true; }); Preference chroot_pref = findPref("chrootDir"); chroot_pref.setSummary(FsSettings.getChrootDirAsString()); chroot_pref.setOnPreferenceClickListener(preference -> { AlertDialog folderPicker = new FolderPickerDialogBuilder(getActivity(), FsSettings.getChrootDir()) .setSelectedButton(R.string.select, path -> { if (preference.getSummary().equals(path)) return; if (!FsSettings.setChrootDir(path)) return; // TODO: this is a hotfix, create correct resources, improve UI/UX final File root = new File(path); if (!root.canRead()) { Toast.makeText(getActivity(), "Notice that we can't read/write in this folder.", Toast.LENGTH_LONG).show(); } else if (!root.canWrite()) { Toast.makeText(getActivity(), "Notice that we can't write in this folder, reading will work. Writing in sub folders might work.", Toast.LENGTH_LONG).show(); } preference.setSummary(path); stopServer(); }).setNegativeButton(R.string.cancel, null).create(); folderPicker.show(); return true; }); final CheckBoxPreference wakelock_pref = findPref("stayAwake"); wakelock_pref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); final CheckBoxPreference writeExternalStorage_pref = findPref("writeExternalStorage"); String externalStorageUri = FsSettings.getExternalStorageUri(); if (externalStorageUri == null) { writeExternalStorage_pref.setChecked(false); } writeExternalStorage_pref.setOnPreferenceChangeListener((preference, newValue) -> { if ((boolean) newValue) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, ACTION_OPEN_DOCUMENT_TREE); return false; } else { FsSettings.setExternalStorageUri(null); return true; } }); ListPreference theme = findPref("theme"); theme.setSummary(theme.getEntry()); theme.setOnPreferenceChangeListener((preference, newValue) -> { theme.setSummary(theme.getEntry()); getActivity().recreate(); return true; }); Preference help = findPref("help"); help.setOnPreferenceClickListener(preference -> { Cat.v("On preference help clicked"); Context context = getActivity(); AlertDialog ad = new AlertDialog.Builder(context).setTitle(R.string.help_dlg_title) .setMessage(R.string.help_dlg_message).setPositiveButton(android.R.string.ok, null).create(); ad.show(); Linkify.addLinks((TextView) ad.findViewById(android.R.id.message), Linkify.ALL); return true; }); Preference about = findPref("about"); about.setOnPreferenceClickListener(preference -> { startActivity(new Intent(getActivity(), AboutActivity.class)); return true; }); }
From source file:io.v.android.impl.google.services.blessing.BlessingActivity.java
private void getBlessing() { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS); if (permissionCheck == PackageManager.PERMISSION_DENIED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.GET_ACCOUNTS }, REQUEST_CODE_USER_APPROVAL); return;/* w w w . jav a2 s . c om*/ } Account[] accounts = AccountManager.get(this).getAccountsByType("com.google"); Account account = null; for (int i = 0; i < accounts.length; i++) { if (accounts[i].name.equals(mGoogleAccount)) { account = accounts[i]; } } if (account == null) { replyWithError("Couldn't find Google account with name: " + mGoogleAccount); return; } AccountManager.get(this).getAuthToken(account, OAUTH_SCOPE, new Bundle(), false, new OnTokenAcquired(), new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { replyWithError("Error getting auth token: " + msg.toString()); return true; } })); }
From source file:org.namelessrom.devicecontrol.activities.BaseActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case REQ_PERMISSIONS: { boolean grantedAll = true; if (grantResults.length > 0) { for (final int result : grantResults) { if (result == PackageManager.PERMISSION_DENIED) { grantedAll = false;//from w ww. j a v a 2 s . c o m } } } else { grantedAll = false; } Timber.d("Granted all permissions: %s", grantedAll); // TODO: show warning? return; } } super.onRequestPermissionsResult(requestCode, permissions, grantResults); }