Last active
March 9, 2018 12:42
-
-
Save douglasrafael/1dc7dfcdae119efe8ad9ec0f3b5aa6d1 to your computer and use it in GitHub Desktop.
Android Utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| View focusView = null; | |
| focusView = mPasswordView; | |
| focusView.requestFocus(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private boolean mayRequestContacts() { | |
| if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | |
| return true; | |
| } | |
| if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { | |
| return true; | |
| } | |
| if (shouldShowRequestPermissionRationale(READ_CONTACTS)) { | |
| Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE) | |
| .setAction(android.R.string.ok, new View.OnClickListener() { | |
| @Override | |
| @TargetApi(Build.VERSION_CODES.M) | |
| public void onClick(View v) { | |
| requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); | |
| } | |
| }); | |
| } else { | |
| requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); | |
| } | |
| return false; | |
| } | |
| /** | |
| * Callback received when a permissions request has been completed. | |
| */ | |
| @Override | |
| public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, | |
| @NonNull int[] grantResults) { | |
| if (requestCode == REQUEST_READ_CONTACTS) { | |
| if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |
| populateAutoComplete(); | |
| } | |
| } | |
| } | |
| // https://developer.android.com/training/permissions/requesting.html?hl=pt-br |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment