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:ar.org.fsadosky.iptablesmanager.fragment.ApplicationsListFragment.java
private ArrayList<ApplicationItem> getDeviceApplications() { final PackageManager packageManager = getActivity().getPackageManager(); List<ApplicationInfo> installedApplications = packageManager .getInstalledApplications(PackageManager.GET_META_DATA); Map<Integer, ApplicationItem> applicationItemMap = new HashMap<Integer, ApplicationItem>(); for (ApplicationInfo applicationInfo : installedApplications) { if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.INTERNET, applicationInfo.packageName)) { String appName = (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "(unknown)"); Uri appIconUri = null;//from w w w. j a v a 2 s . com if (applicationInfo.icon != 0) { appIconUri = Uri.parse( "android.resource://" + applicationInfo.packageName + "/" + applicationInfo.icon); } int appUid = applicationInfo.uid; if (applicationItemMap.containsKey(appUid)) { ApplicationItem applicationItem = applicationItemMap.get(appUid); applicationItem.addApplication(appName); applicationItemMap.put(appUid, applicationItem); } else { applicationItemMap.put(appUid, new ApplicationItem(appIconUri, appName, appUid)); } } } return new ArrayList<ApplicationItem>(applicationItemMap.values()); }
From source file:io.v.android.apps.syncslides.SignInActivity.java
private void pickAccountDone(String accountName) { mAccountName = accountName;//from w w w . j a v a 2 s.c o m SharedPreferences.Editor editor = mPrefs.edit(); editor.putString(PREF_USER_ACCOUNT_NAME, accountName); editor.commit(); int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { requestContactsDone(); return; } ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.GET_ACCOUNTS }, REQUEST_CODE_READ_CONTACTS); }
From source file:com.android.browser.DownloadHandler.java
/** * Notify the host application a download should be done, even if there * is a streaming viewer available for this type. * @param activity Activity requesting the download. * @param url The full url to the content that should be downloaded * @param userAgent User agent of the downloading application. * @param contentDisposition Content-disposition http header, if present. * @param mimetype The mimetype of the content reported by the server * @param referer The referer associated with the downloaded url * @param privateBrowsing If the request is coming from a private browsing tab. *//*from w ww . j av a 2s .c om*/ /*package */ static void onDownloadStartNoStream(Activity activity, String url, String userAgent, String contentDisposition, String mimetype, String referer, boolean privateBrowsing) { // Check permissions first when download will be start. int permissionCheck = ContextCompat.checkSelfPermission(activity, android.Manifest.permission.WRITE_EXTERNAL_STORAGE); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { onDownloadNoStreamImpl(activity, url, userAgent, contentDisposition, mimetype, referer, privateBrowsing); } else { pendingDownloadBundle = PendingDownloadBundle.create(url, userAgent, contentDisposition, mimetype, referer, privateBrowsing); // Permission not granted, request it from the user ActivityCompat.requestPermissions(activity, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, BrowserActivity.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } }
From source file:android.example.com.visualizerpreferences.VisualizerActivity.java
/** * App Permissions for Audio/*from w ww .j a v a2 s. c om*/ **/ private void setupPermissions() { // If we don't have the record audio permission... if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { // And if we're on SDK M or later... if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Ask again, nicely, for the permissions. String[] permissionsWeNeed = new String[] { Manifest.permission.RECORD_AUDIO }; requestPermissions(permissionsWeNeed, MY_PERMISSION_RECORD_AUDIO_REQUEST_CODE); } } else { // Otherwise, permissions were granted and we are ready to go! mAudioInputReader = new AudioInputReader(mVisualizerView, this); } }
From source file:co.codecrunch.musicplayerlite.activities.MusicPlayerBaseActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case 124: {//from w ww . j a v a 2 s . c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) loadAlreadyPlayng(); } } break; default: super.onRequestPermissionsResult(requestCode, permissions, grantResults); } }
From source file:br.com.brolam.cloudvision.ui.NoteVisionActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_note_vision); this.toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w . j a v a2 s. c o m*/ // Show the Up button in the action bar. ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); this.fabFlashOnOff = (FloatingActionButton) this.findViewById(R.id.fabFlashOnOff); this.fabCameraPlayStop = (FloatingActionButton) this.findViewById(R.id.fabCameraPlayStop); this.fabAdd = (FloatingActionButton) this.findViewById(R.id.fabAdd); this.contentNoteVisionCamera = this.findViewById(R.id.contentNoteVisionCamera); this.contentNoteVisionKeyboard = this.findViewById(R.id.contentNoteVisionKeyboard); this.editTextTitle = (EditText) this.findViewById(R.id.editTextTitle); this.editTextContent = (EditText) this.findViewById(R.id.editTextContent); setSaveInstanceState(savedInstanceState); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(); } else { ActivityHelper.requestCameraPermission(TAG, this, mGraphicOverlay); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); /* * Criar um LoginHelper para registrar o login do usurio no aplicativo. * Veja os mtodos onResume, onPause e onActivityResult para mais detalhes * sobre o fluxo de registro do usurio. */ this.loginHelper = new LoginHelper(this, null, this); }
From source file:com.seamusdawkins.autocomplete.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case REQUEST_PERMISSION: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Add your function here which open camera } else {/*from www . j a v a 2s. co m*/ } return; } } }
From source file:com.ae.apps.tripmeter.fragments.expenses.TripsListFragment.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case PERMISSIONS_REQUEST_READ_CONTACTS: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { createExpenseView();/*from www.j a v a2 s . co m*/ } else { Toast.makeText(getActivity(), R.string.str_permission_contacts_reason, Toast.LENGTH_SHORT).show(); } break; } default: { super.onRequestPermissionsResult(requestCode, permissions, grantResults); } } }
From source file:com.adevani.mytube.MainActivity.java
/** * Check if we have the GET_ACCOUNTS permission and request it if we do not. * @return true if we have the permission, false if we do not. *//*from ww w .j av a 2 s.c o m*/ private boolean checkAccountsPermission() { final String perm = Manifest.permission.GET_ACCOUNTS; int permissionCheck = ContextCompat.checkSelfPermission(this, perm); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { // We have the permission return true; } else if (ActivityCompat.shouldShowRequestPermissionRationale(this, perm)) { // Need to show permission rationale, display a snackbar and then request // the permission again when the snackbar is dismissed. Snackbar.make(findViewById(R.id.main_layout), R.string.contacts_permission_rationale, Snackbar.LENGTH_INDEFINITE).setAction(android.R.string.ok, new View.OnClickListener() { @Override public void onClick(View v) { // Request the permission again. ActivityCompat.requestPermissions(MainActivity.this, new String[] { perm }, RC_PERM_GET_ACCOUNTS); } }).show(); return false; } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[] { perm }, RC_PERM_GET_ACCOUNTS); return false; } }
From source file:cn.moon.superwechat.runtimepermissions.PermissionsManager.java
/** * This static method can be used to check whether or not you have a specific permission. * It is basically a less verbose method of using {@link ActivityCompat#checkSelfPermission(Context, String)} * and will simply return a boolean whether or not you have the permission. If you pass * in a null Context object, it will return false as otherwise it cannot check the permission. * However, the Activity parameter is nullable so that you can pass in a reference that you * are not always sure will be valid or not (e.g. getActivity() from Fragment). * * @param context the Context necessary to check the permission * @param permission the permission to check * @return true if you have been granted the permission, false otherwise *///from w w w . ja va 2 s. c o m @SuppressWarnings("unused") public synchronized boolean hasPermission(@Nullable Context context, @NonNull String permission) { return context != null && (ActivityCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED || !mPermissions.contains(permission)); }