List of usage examples for android.content.pm PackageManager PERMISSION_GRANTED
int PERMISSION_GRANTED
To view the source code for android.content.pm PackageManager PERMISSION_GRANTED.
Click Source Link
From source file:com.wiret.arbrowser.AbstractArchitectCamActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case 101: {/*from w w w .j a v a2 s . c om*/ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { try { this.setContentView(this.getContentViewId()); initArView(); } catch (Exception rex) { this.architectView = null; AbstractArchitectCamActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(AbstractArchitectCamActivity.this, "AR not supported by this device.", Toast.LENGTH_LONG).show(); } }); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); finish(); } postCreateArView(); if (kmlFile != null) { importData(kmlFile.getPath()); } } return; } } }
From source file:com.ag.common.permission.EasyPermissions.java
/** * Handle the result of a permission request, should be called from the calling Activity's * {@link android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])} * method.//w w w .ja v a2s .c o m * <p/> * If any permissions were granted or denied, the Activity will receive the appropriate * callbacks through {@link PermissionCallbacks} and methods annotated with * {@link AfterPermissionGranted} will be run if appropriate. * * @param requestCode requestCode argument to permission result callback. * @param permissions permissions argument to permission result callback. * @param grantResults grantResults argument to permission result callback. * @param object the calling Activity or Fragment. * @throws IllegalArgumentException if the calling Activity does not implement * {@link PermissionCallbacks}. */ public static void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults, Object object) { checkCallingObjectSuitability(object); PermissionCallbacks callbacks = (PermissionCallbacks) object; // Make a collection of granted and denied permissions from the request. ArrayList<String> granted = new ArrayList<>(); ArrayList<String> denied = new ArrayList<>(); for (int i = 0; i < permissions.length; i++) { String perm = permissions[i]; if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { granted.add(perm); } else { denied.add(perm); } } // Report granted permissions, if any. if (!granted.isEmpty()) { // Notify callbacks callbacks.onPermissionsGranted(requestCode, granted); } // Report denied permissions, if any. if (!denied.isEmpty()) { callbacks.onPermissionsDenied(requestCode, denied); } // If 100% successful, call annotated methods if (!granted.isEmpty() && denied.isEmpty()) { runAnnotatedMethods(object, requestCode); } }
From source file:com.amaze.carbonfilemanager.fragments.preference_fragments.Preffrag.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); utilsProvider = (UtilitiesProviderInterface) getActivity(); PreferenceUtils.reset();/*from w w w.j a v a 2 s .co m*/ // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); for (String PREFERENCE_KEY : PREFERENCE_KEYS) { findPreference(PREFERENCE_KEY).setOnPreferenceClickListener(this); } gplus = (CheckBox) findPreference("plus_pic"); if (BuildConfig.IS_VERSION_FDROID) gplus.setEnabled(false); // crypt master password final EditTextPreference masterPasswordPreference = (EditTextPreference) findPreference( PREFERENCE_CRYPT_MASTER_PASSWORD); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { // encryption feature not available masterPasswordPreference.setEnabled(false); } if (sharedPref.getBoolean(PREFERENCE_CRYPT_FINGERPRINT, false)) { masterPasswordPreference.setEnabled(false); } CheckBox checkBoxFingerprint = (CheckBox) findPreference(PREFERENCE_CRYPT_FINGERPRINT); try { // finger print sensor final FingerprintManager fingerprintManager = (FingerprintManager) getActivity() .getSystemService(Context.FINGERPRINT_SERVICE); final KeyguardManager keyguardManager = (KeyguardManager) getActivity() .getSystemService(Context.KEYGUARD_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && fingerprintManager.isHardwareDetected()) { checkBoxFingerprint.setEnabled(true); } checkBoxFingerprint.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_no_permission), Toast.LENGTH_LONG).show(); return false; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !fingerprintManager.hasEnrolledFingerprints()) { Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_not_enrolled), Toast.LENGTH_LONG).show(); return false; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !keyguardManager.isKeyguardSecure()) { Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_no_security), Toast.LENGTH_LONG) .show(); return false; } masterPasswordPreference.setEnabled(false); return true; } }); } catch (NoClassDefFoundError error) { error.printStackTrace(); // fingerprint manager class not defined in the framework checkBoxFingerprint.setEnabled(false); } // Hide root preference Preference mRootMode = findPreference("rootmode"); PreferenceCategory mMisc = (PreferenceCategory) findPreference("misc"); mMisc.removePreference(mRootMode); }
From source file:com.adkdevelopment.earthquakesurvival.ui.MapviewFragment.java
/** * Adds my location button to the MapView. *//* ww w . jav a 2 s . c om*/ private void addMyLocation() { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION }, LOCATION_PERMISSION); } else { mGoogleMap.setMyLocationEnabled(true); } }
From source file:com.aengbee.android.leanback.ui.SearchFragment.java
private boolean hasPermission(final String permission) { final Context context = getActivity(); return PackageManager.PERMISSION_GRANTED == context.getPackageManager().checkPermission(permission, context.getPackageName());// w ww . ja va 2 s. c o m }
From source file:cn.finalteam.galleryfinal.permission.EasyPermissions.java
/** * Handle the result of a permission request, should be called from the calling Activity's * {@link android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])} * method.// w w w . java 2 s .c o m * <p/> * If any permissions were granted or denied, the Activity will receive the appropriate * callbacks through {@link PermissionCallbacks} and methods annotated with * {@link AfterPermissionGranted} will be run if appropriate. * * @param requestCode requestCode argument to permission result callback. * @param permissions permissions argument to permission result callback. * @param grantResults grantResults argument to permission result callback. * @param object the calling Activity or Fragment. * @throws IllegalArgumentException if the calling Activity does not implement * {@link PermissionCallbacks}. */ public static void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults, Object object) { checkCallingObjectSuitability(object); PermissionCallbacks callbacks = (PermissionCallbacks) object; // Make a collection of granted and denied permissions from the request. ArrayList<String> granted = new ArrayList<>(); ArrayList<String> denied = new ArrayList<>(); for (int i = 0; i < permissions.length; i++) { String perm = permissions[i]; if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { granted.add(perm); } else { denied.add(perm); } } // Report granted permissions, if any. if (!granted.isEmpty()) { // Notify callbacks callbacks.onPermissionsGranted(granted); } // Report denied permissions, if any. if (!denied.isEmpty()) { callbacks.onPermissionsDenied(denied); } // If 100% successful, call annotated methods if (!granted.isEmpty() && denied.isEmpty()) { runAnnotatedMethods(object, requestCode); } }
From source file:ai.api.AIService.java
protected boolean checkPermissions() { boolean granted = true; try {/* ww w . j ava 2s .c o m*/ granted = ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED; } catch (final Throwable ignored) { } return granted; }
From source file:atlc.granadaaccessibilityranking.VoiceActivity.java
/** * Processes the result of the record audio permission request. If it is not granted, the * abstract method "onRecordAudioPermissionDenied" method is invoked. Such method must be implemented * by the subclasses of VoiceActivity.//ww w . j a v a2s.c o m * More info: http://developer.android.com/intl/es/training/permissions/requesting.html * */ @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { if (requestCode == MY_PERMISSIONS_REQUEST_RECORD_AUDIO) { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.i(LOGTAG, "Record audio permission granted"); } else { Log.i(LOGTAG, "Record audio permission denied"); onRecordAudioPermissionDenied(); } } }
From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java
/** * This method checks a single permission at runtime. Required for Android versions Marshmallow (API version 23) and higher. * The request code must be handled in the onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) method * which has to be overridden in each activity that needs to request runtime permission. * * @param context the context/* w w w . j a v a 2 s. co m*/ * @param requestCode the request code to be handled in the onRequestPermissionsResult method of the calling activity * @param permission the requested permission * @param dialogTitle the dialog title for the rationale * @param dialogMessage the dialog message for the rationale * @return true if permission is granted, false otherwise */ public static boolean checkSinglePermission(@NonNull final Context context, final int requestCode, @NonNull final String permission, final String dialogTitle, final String dialogMessage, final boolean showRequestPermissionRationale) { int currentAPIVersion = Build.VERSION.SDK_INT; if (currentAPIVersion >= android.os.Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { if (showRequestPermissionRationale && ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission)) { AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context); alertBuilder.setCancelable(true); alertBuilder.setTitle(dialogTitle); alertBuilder.setMessage(dialogMessage); alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ActivityCompat.requestPermissions((Activity) context, new String[] { permission }, requestCode); } }); AlertDialog alert = alertBuilder.create(); alert.show(); } else { ActivityCompat.requestPermissions((Activity) context, new String[] { permission }, requestCode); } return false; } else { return true; } } else { return true; } }
From source file:com.alusorstroke.jjvm.MainActivity.java
@SuppressLint("NewApi") @Override/* w ww. ja va2 s . c o m*/ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case 1: boolean foundfalse = false; for (int i = 0; i < grantResults.length; i++) { if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { foundfalse = true; } } if (!foundfalse) { openNavigationItem(queueItem); } else { // Permission Denied Toast.makeText(MainActivity.this, getResources().getString(R.string.permissions_required), Toast.LENGTH_SHORT).show(); } break; default: super.onRequestPermissionsResult(requestCode, permissions, grantResults); } }