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:github.popeen.dsub.activity.SubsonicActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { } else {//w w w .j a v a2s.c om Util.toast(this, R.string.permission_external_storage_failed); finish(); } } } }
From source file:com.alusorstroke.jjvm.MainActivity.java
/** * Checks if the item can be opened because it has sufficient permissions. * @param item The item to check/* ww w . jav a 2 s . com*/ * @param fragment The fragment instance associated to this item. * @return true if the item is safe to open */ private boolean checkPermissionsHandleIfNeeded(NavItem item, Fragment fragment) { if (fragment instanceof PermissionsFragment && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { String[] permissions = ((PermissionsFragment) fragment).requiredPermissions(); boolean allGranted = true; for (String permission : permissions) { if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) allGranted = false; } if (!allGranted) { //TODO An explaination before asking requestPermissions(permissions, 1); queueItem = item; return false; } return true; } return true; }
From source file:app.axe.imooc.zxing.app.CaptureActivity.java
@SuppressWarnings("deprecation") @Override//from w ww . ja va 2s . co m protected void onResume() { super.onResume(); resetStatusView(); if (hasSurface) { // The activity was paused but not stopped, so the surface still // exists. Therefore // surfaceCreated() won't be called, so init the camera here. if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.CAMERA }, MY_PERMISSIONS_REQUEST_CAMERA); } else { initCamera(surfaceHolder); } } else { // Install the callback and wait for surfaceCreated() to init the // camera. Log.e("CaptureActivity", "onResume"); } Intent intent = getIntent(); String action = intent == null ? null : intent.getAction(); String dataString = intent == null ? null : intent.getDataString(); if (intent != null && action != null) { if (action.equals(Intents.Scan.ACTION)) { // Scan the formats the intent requested, and return the result // to the calling activity. source = Source.NATIVE_APP_INTENT; decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); } else if (dataString != null && dataString.contains(PRODUCT_SEARCH_URL_PREFIX) && dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) { // Scan only products and send the result to mobile Product // Search. source = Source.PRODUCT_SEARCH_LINK; sourceUrl = dataString; decodeFormats = DecodeFormatManager.PRODUCT_FORMATS; } else if (dataString != null && dataString.startsWith(ZXING_URL)) { // Scan formats requested in query string (all formats if none // specified). // If a return URL is specified, send the results there. // Otherwise, handle it ourselves. source = Source.ZXING_LINK; sourceUrl = dataString; Uri inputUri = Uri.parse(sourceUrl); returnUrlTemplate = inputUri.getQueryParameter(RETURN_URL_PARAM); decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri); } else { // Scan all formats and handle the results ourselves (launched // from Home). source = Source.NONE; decodeFormats = null; } characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET); } else { source = Source.NONE; decodeFormats = null; characterSet = null; } beepManager.updatePrefs(); }
From source file:com.bwash.bwashcar.activities.CompanyActivity.java
private void takePhoto() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN // Permission was added in API Level 16 && ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, getString(R.string.permission_write_storage_rationale), REQUEST_STORAGE_WRITE_ACCESS_PERMISSION); } else {// w ww . j a va 2s. c om mSelectPicturePopupWindow.dismissPopupWindow(); Intent takeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //???? takeIntent.putExtra(MediaStore.EXTRA_OUTPUT, sourceUri); startActivityForResult(takeIntent, CAMERA_REQUEST_CODE); } }
From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java
/** * This method is used in the host application in the onRequestPermissionsResult method in case if a PUSH feedback is triggered. * * @param requestCode the request code to be handled in the onRequestPermissionsResult method of the calling activity * @param permissions the permissions/* www . j a v a 2s.c o m*/ * @param grantResults the granted results * @param activity the activity from where the method is called * @param permission the requested permission * @param dialogTitle the dialog title for the rationale * @param dialogMessage the dialog message for the rationale */ public static void onRequestPermissionsResultCase(final int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults, @NonNull final Activity activity, @NonNull final String permission, final int dialogTitle, final int dialogMessage, final long applicationId, @NonNull final String baseURL, @NonNull final String language) { final Intent intent = new Intent(activity, FeedbackActivity.class); intent.putExtra(FeedbackActivity.EXTRA_KEY_APPLICATION_ID, applicationId); intent.putExtra(FeedbackActivity.EXTRA_KEY_BASE_URL, baseURL); intent.putExtra(FeedbackActivity.EXTRA_KEY_LANGUAGE, language); if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Permission was already granted. Taking a screenshot of the current screen automatically and open the FeedbackActivity from the feedback library startActivity(activity, intent, baseURL, true); } else { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { // The user denied the permission without checking 'Never ask again'. Show the rationale AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity); alertBuilder.setTitle(dialogTitle); alertBuilder.setMessage(dialogMessage); alertBuilder.setPositiveButton(R.string.supersede_feedbacklibrary_retry_string, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ActivityCompat.requestPermissions(activity, new String[] { permission }, requestCode); } }); alertBuilder.setNegativeButton(R.string.supersede_feedbacklibrary_not_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); startActivity(activity, intent, baseURL, false); } }); alertBuilder.setCancelable(false); alertBuilder.show(); } else { // Open the FeedbackActivity from the feedback library without automatically taking a screenshot startActivity(activity, intent, baseURL, false); } } }
From source file:me.kartikarora.transfersh.activities.TransferActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == FileGridAdapter.PERM_REQUEST_CODE && grantResults.length > 0) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) mAdapter.getPermissionRequestResult().onPermitted(); }// w ww . j a v a2 s.c o m }
From source file:br.com.anteros.vendas.gui.AnexoCadastroActivity.java
/** * Evento que ocorre quando o usurio confirmou a requisio de permisso. * @param requestCode Cdigo da requisio/*from w ww. j av a 2 s . co m*/ * @param permissions Permisses * @param grantResults Grants */ @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { /** * Se requestcode for igual 0(Zero) ele confirmou requisio */ if (requestCode == 0) { /** * Verifica se ele aceitou a requisio com as permisses. */ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) { /** * Se j tem permisso inicia a cmera. */ iniciaCamera(); } } /** * Se requestcode for igual 1(Um) ele confirmou requisio */ if (requestCode == 1) { /** * Verifica se ele aceitou a requisio com as permisses. */ if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) { /** * Se j tem permisso abre a galeria. */ anexarArquivos(); } } }
From source file:ar.com.bestprice.buyitnow.barcodereader.BarcodeCaptureActivity.java
/** * Callback for the result from requesting permissions. This method * is invoked for every call on {@link #requestPermissions(String[], int)}. * <p>/*from ww w . j a v a2s .c o m*/ * <strong>Note:</strong> It is possible that the permissions request interaction * with the user is interrupted. In this case you will receive empty permissions * and results arrays which should be treated as a cancellation. * </p> * * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. * @param permissions The requested permissions. Never null. * @param grantResults The grant results for the corresponding permissions * which is either {@link PackageManager#PERMISSION_GRANTED} * or {@link PackageManager#PERMISSION_DENIED}. Never null. * @see #requestPermissions(String[], int) */ @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode != RC_HANDLE_CAMERA_PERM) { Log.d(TAG, "Got unexpected permission result: " + requestCode); super.onRequestPermissionsResult(requestCode, permissions, grantResults); return; } if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d(TAG, "Camera permission granted - initialize the camera source"); // we have permission, so create the camerasource boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, false); boolean useFlash = getIntent().getBooleanExtra(UseFlash, false); createCameraSource(autoFocus, useFlash); return; } Log.e(TAG, "Permission not granted: results len = " + grantResults.length + " Result code = " + (grantResults.length > 0 ? grantResults[0] : "(empty)")); DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Multitracker sample").setMessage(R.string.no_camera_permission) .setPositiveButton(R.string.ok, listener).show(); }
From source file:co.scandy.example.scandycoreandroidexample.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case REQUEST_EXTERNAL_STORAGE: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! enableScanMode(true);//from ww w. ja v a2 s . c o m } else { enableScanMode(false); } break; } } }
From source file:ca.ualberta.cs.drivr.RequestsListAdapter.java
/** * Called when the view holder is wants to bind the request at a certain position in the list. * @param viewHolder/*from w ww.j a va 2s . c o m*/ * @param position */ @Override public void onBindViewHolder(final RequestsListAdapter.ViewHolder viewHolder, final int position) { final Request request = requestsToDisplay.get(position); // Get the views to update final TextView otherUserNameTextView = viewHolder.otherUserNameTextView; final TextView descriptionTextView = viewHolder.descriptionTextView; final TextView fareTextView = viewHolder.fareTextView; final TextView routeTextView = viewHolder.routeTextView; final TextView statusTextView = viewHolder.statusTextView; final ImageView callImageView = viewHolder.callImageView; final ImageView emailImageView = viewHolder.emailImageView; final ImageView checkImageView = viewHolder.checkMarkImageView; final ImageView deleteImageView = viewHolder.xMarkImageView; // Todo Hide Image Views until correct Request State if (request.getRequestState() != RequestState.CONFIRMED) { checkImageView.setVisibility(View.INVISIBLE); } if (request.getRequestState() != RequestState.PENDING) { deleteImageView.setVisibility(View.INVISIBLE); } // Show the other person's name final DriversList drivers = request.getDrivers(); // Get the username of the other user if (userManager.getUserMode() == UserMode.RIDER) { final String multipleDrivers = "Multiple Drivers Accepted"; final String driverUsername = drivers.size() == 1 ? drivers.get(0).getUsername() : "No Driver Yet"; otherUserNameTextView.setText(drivers.size() > 1 ? multipleDrivers : driverUsername); } else { otherUserNameTextView.setText(request.getRider().getUsername()); } // If the request has a description, show it. Otherwise, hide te description if (Strings.isNullOrEmpty(request.getDescription())) descriptionTextView.setVisibility(View.GONE); else descriptionTextView.setText(request.getDescription()); // Show the fare fareTextView.setText("$" + request.getFareString()); // Show the route routeTextView.setText(request.getRoute()); // Driver User otherUserNameTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String otherUsername = otherUserNameTextView.getText().toString(); // there exists drivers if (otherUsername != "No Driver Yet") { if (otherUsername != "Multiple Drivers Accepted") { Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create(); ElasticSearch elasticSearch = new ElasticSearch( UserManager.getInstance().getConnectivityManager()); User user = elasticSearch.loadUser(otherUsername); String driverString = gson.toJson(user, User.class); Intent intent = new Intent(context, DriverProfileActivity.class); intent.putExtra(DriverProfileActivity.DRIVER, driverString); context.startActivity(intent); } else { startMultipleDriverIntent(request); } } } }); routeTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create(); String requestString = gson.toJson(request, Request.class); Intent intent = new Intent(context, RequestActivity.class); intent.putExtra("UniqueID", "From_RequestListActivity"); intent.putExtra(RequestActivity.EXTRA_REQUEST, requestString); context.startActivity(intent); } }); // Show the status text statusTextView.setText(request.getRequestState().toString()); // Add a listener to the call image callImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (drivers.size() == 0) { Toast.makeText(context, "No driver number available at this time", Toast.LENGTH_SHORT).show(); } // Start Dialer else if (drivers.size() == 1) { Intent intent = new Intent(Intent.ACTION_CALL); String number; if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) { number = drivers.get(0).getPhoneNumber(); } else { number = request.getRider().getPhoneNumber(); } number = "tel:" + number; intent.setData(Uri.parse(number)); if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { return; } context.startActivity(intent); } else { startMultipleDriverIntent(request); } } }); // Add a listener to the email image emailImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (drivers.size() == 0) { Toast.makeText(context, "No driver email available at this time", Toast.LENGTH_SHORT).show(); } //http://stackoverflow.com/questions/8701634/send-email-intent else if (drivers.size() == 1) { Intent intent = new Intent(); ComponentName emailApp = intent.resolveActivity(context.getPackageManager()); ComponentName unsupportedAction = ComponentName .unflattenFromString("com.android.fallback/.Fallback"); boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction); String email; if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) { email = drivers.get(0).getEmail(); } else { email = request.getRider().getEmail(); } String subject = "Drivr Request: " + request.getId(); String body = "Drivr user " + drivers.get(0).getUsername(); if (hasEmailApp) { Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(Intent.EXTRA_TEXT, body); context.startActivity(Intent.createChooser(emailIntent, "Chooser Title")); } else { Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, ""); emailIntent.putExtra(Intent.EXTRA_TEXT, ""); context.startActivity(Intent.createChooser(emailIntent, "Send email...")); } } else { startMultipleDriverIntent(request); } } }); // Complete The Request checkImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, RequestCompletedActivity.class); intent.putExtra(RequestCompletedActivity.REQUEST_ID_EXTRA, request.getId()); context.startActivity(intent); } }); deleteImageView.setOnClickListener(new View.OnClickListener() { // Todo Delete the Request @Override public void onClick(View v) { v.getContext(); ElasticSearch elasticSearch = new ElasticSearch( (ConnectivityManager) v.getContext().getSystemService(Context.CONNECTIVITY_SERVICE)); elasticSearch.deleteRequest(request.getId()); UserManager userManager = UserManager.getInstance(); userManager.getRequestsList().removeById(request); userManager.notifyObservers(); requestsToDisplay.remove(request); notifyItemRemoved(viewHolder.getAdapterPosition()); } }); }