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:cn.xcom.helper.activity.AuthorizedActivity.java
private void showPickDialog() { new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT) .setNegativeButton("", new DialogInterface.OnClickListener() { @Override/*from ww w . j av a 2 s. co m*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent albumIntent = new Intent(); albumIntent.setType("image/*"); albumIntent.setAction(Intent.ACTION_PICK); startActivityForResult(albumIntent, PHOTO_REQUEST_ALBUM); } }).setPositiveButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); int permissionCheck = ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { File path = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); File file = new File(path, "51helper.jpg"); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); } startActivityForResult(cameraIntent, PHOTO_REQUEST_CAMERA); } else if (permissionCheck == PackageManager.PERMISSION_DENIED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) mContext, Manifest.permission.CAMERA)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions((Activity) mContext, new String[] { Manifest.permission.CAMERA }, MY_PERMISSIONS_REQUEST_READ_CONTACTS); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } } }).show(); }
From source file:org.awesomeapp.messenger.ui.AddContactActivity.java
boolean hasCameraPermission() { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_DENIED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, MY_PERMISSIONS_REQUEST_CAMERA); return false; } else {//from www. ja va2 s . c o m return true; } }
From source file:im.ene.lab.toro.sample.activity.MainActivity.java
@Override protected void onResume() { super.onResume(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 1000); } else {/* w w w .jav a 2 s. co m*/ try { Log.e(TAG, "onResume: " + Arrays.toString(Util.loadMovieFolder())); } catch (FileNotFoundException e) { Log.e(TAG, "onResume: " + e.getLocalizedMessage()); e.printStackTrace(); } } } }
From source file:com.jecelyin.editor.v2.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); pref = Pref.getInstance(this); MenuManager.init(this); setContentView(R.layout.main_activity); L.d(TAG, "onCreate"); CrashDbHelper.getInstance(this).close(); //? mToolbar = (Toolbar) findViewById(R.id.toolbar); mLoadingLayout = (LinearLayout) findViewById(R.id.loading_layout); mTabPager = (TabViewPager) findViewById(R.id.tab_pager); mMenuRecyclerView = (RecyclerView) findViewById(R.id.menuRecyclerView); mDrawerLayout = (AnyDrawerLayout) findViewById(R.id.drawer_layout); mTabRecyclerView = (RecyclerView) findViewById(R.id.tabRecyclerView); mVersionTextView = (TextView) findViewById(R.id.versionTextView); findViewById(R.id.changeThemeBtn).setOnClickListener(new View.OnClickListener() { @Override/*w w w. ja va 2 s . co m*/ public void onClick(View v) { new ChangeThemeDialog(getContext()).show(); } }); SymbolBarLayout symbolBarLayout = (SymbolBarLayout) findViewById(R.id.symbolBarLayout); symbolBarLayout.setOnSymbolCharClickListener(new SymbolBarLayout.OnSymbolCharClickListener() { @Override public void onClick(View v, String text) { insertText(text); } }); if (!AppUtils.verifySign(getContext())) { UIUtils.showConfirmDialog(getContext(), getString(R.string.verify_sign_failure), new UIUtils.OnClickCallback() { @Override public void onOkClick() { SysUtils.startWebView(getContext(), "https://github.com/jecelyin/920-text-editor-v2/releases"); } }); } setStatusBarColor(mDrawerLayout); bindPreferences(); setScreenOrientation(); mDrawerLayout.setEnabled(false); mDrawerLayout.setScrimColor(Color.TRANSPARENT); String version = SysUtils.getVersionName(this); mVersionTextView.setText(version); if (savedInstanceState == null && pref.isAutoCheckUpdates()) { new CheckUpgradeTask(this).checkVersion(version); } if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED || ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { requestWriteExternalStoragePermission(); } else { start(); } }
From source file:br.edu.ufabc.padm.cardioufabc.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == WRITE_EXTERNAL_STORAGE_REQ_CODE) { // como as permisses so solicitadas individualmente, basta verificar apenas o primeiro if (grantResults.length > 0) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { permissible.onPermissionGranted(permissions[0]); } else if (grantResults[0] == PackageManager.PERMISSION_DENIED) { boolean showRationale = ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0]); // "never ask again" habilitado if (!showRationale) { permissible.onNeverAskAgain(permissions[0]); }/*from ww w.ja va2 s . c om*/ } } } }
From source file:com.example.captain_miao.grantap.ShadowPermissionActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { ArrayList<String> deniedPermissions = new ArrayList<>(); for (int i = 0; i < permissions.length; i++) { String permission = permissions[i]; if (grantResults[i] == PackageManager.PERMISSION_DENIED) { deniedPermissions.add(permission); }// w ww. j ava 2 s . c o m } if (deniedPermissions.isEmpty()) { permissionGranted(); } else { showPermissionDenyDialog(deniedPermissions); } }
From source file:org.dkf.jmule.util.DangerousPermissionsChecker.java
private boolean onExternalStoragePermissionsResult(String[] permissions, int[] grantResults) { if (!Ref.alive(activityRef)) { return false; }//from w ww . j a v a 2 s .c o m final Activity activity = activityRef.get(); for (int i = 0; i < permissions.length; i++) { if (grantResults[i] == PackageManager.PERMISSION_DENIED) { if (permissions[i].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE) || permissions[i].equals(Manifest.permission.READ_EXTERNAL_STORAGE)) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setIcon(R.drawable.sd_card_notification); builder.setTitle(R.string.why_we_need_storage_permissions); builder.setMessage(R.string.why_we_need_storage_permissions_summary); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { shutdownFrostWire(); } }); builder.setPositiveButton(R.string.request_again, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { requestPermissions(); } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); return false; } } } return true; }
From source file:com.mycompany.myfirstindoorsapp.PagedActivity.java
/** * The Android system calls us back/*from w w w . j ava2 s .c o m*/ * after the user has granted permissions (or denied them) * * @param requestCode * @param permissions * @param grantResults */ @TargetApi(Build.VERSION_CODES.M) @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == REQUEST_CODE_PERMISSIONS) { // Since we have requested multiple permissions, // we need to check if any were denied for (int grant : grantResults) { if (grant == PackageManager.PERMISSION_DENIED) { if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_COARSE_LOCATION)) { // User has *NOT* allowed us to use ACCESS_COARSE_LOCATION // permission on first try. This is the last chance we get // to ask the user, so we explain why we want this permission Toast.makeText(this, "Location is used for Bluetooth location", Toast.LENGTH_SHORT).show(); // Re-ask for permission requestPermissionsFromUser(); return; } // The user has finally denied us permissions. Toast.makeText(this, "Cannot continue without permissions.", Toast.LENGTH_SHORT).show(); this.finishAffinity(); return; } } checkLocationIsEnabled(); } }
From source file:com.justinbull.ichnaeachecker.MainActivity.java
public void setCellInfo() { int tmPermCheck = ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION); if (tmPermCheck == PackageManager.PERMISSION_GRANTED) { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 && tm.getAllCellInfo() != null) { mVisibleCells = GeneralCellInfoFactory.getInstances(tm.getAllCellInfo()); // Sort cells by strength Collections.sort(mVisibleCells, new Comparator<GeneralCellInfo>() { @Override/*www . j ava2 s. c o m*/ public int compare(GeneralCellInfo lhs, GeneralCellInfo rhs) { int lhsDbm = lhs.getAsuStrength(); int rhsDbm = rhs.getAsuStrength(); if (lhsDbm == rhsDbm) { return 0; } return lhsDbm > rhsDbm ? -1 : 1; } }); mRegisteredCells.clear(); if (mVisibleCells.size() == 0) { Log.w(TAG, "setCellInfo: No visible cells (primary or neighbours), unable to do anything"); } for (GeneralCellInfo cell : mVisibleCells) { Log.i(TAG, "Device aware of " + cell.toString()); if (cell.isRegistered()) { mRegisteredCells.add(cell); } } if (mRegisteredCells.isEmpty()) { Log.w(TAG, "setCellInfo: No registered cells, nothing to select."); mSelectedCell = null; } else { Log.i(TAG, "setCellInfo: Preselected strongest registered cell: " + mRegisteredCells.get(0)); mSelectedCell = mRegisteredCells.get(0); } } else { Log.e(TAG, "setCellInfo: Android device too old to use getAllCellInfo(), need to implement getCellLocation() fallback!"); } mCellListAdapter = new ArrayAdapter<GeneralCellInfo>(this, android.R.layout.simple_list_item_1, mVisibleCells); } else if (tmPermCheck == PackageManager.PERMISSION_DENIED) { if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION)) { Toast.makeText(MainActivity.this, "Dude we need permissions", Toast.LENGTH_LONG).show(); } ActivityCompat.requestPermissions(MainActivity.this, new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION }, Consts.REQUEST_COARSE_LOCATION); } else { Log.wtf(TAG, "setCellInfo: Received unknown int from ContextCompat.checkSelfPermission()"); } }