本文整理汇总了Java中android.content.pm.PackageManager.PERMISSION_GRANTED属性的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.PERMISSION_GRANTED属性的具体用法?Java PackageManager.PERMISSION_GRANTED怎么用?Java PackageManager.PERMISSION_GRANTED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.PERMISSION_GRANTED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRequestPermissionsResult
/**
* 用户权限申请的回调方法
*
* @param requestCode 请求码
* @param permissions 请求的所有权限
* @param grantResults 权限的结果
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSION) {
if (Build.VERSION.SDK_INT >= 23) {
for (int i = 0; i < grantResults.length; ++i) {
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
// 判断用户是否 点击了不再提醒。(检测该权限是否还可以申请)
boolean b = shouldShowRequestPermissionRationale(permissions[i]);
if (!b) {
// 用户还是想用我的 APP 的
// 提示用户去应用设置界面手动开启权限
showDialogTipUserGoToAppSetting();
} else
finish();
}
}
}
}
}
示例2: decodeImage
private void decodeImage() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
int result = ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE);
if (result != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getContext(), R.string.read_permission_msg, Toast.LENGTH_SHORT).show();
String[] permissions = {Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
requestPermissions(permissions, REQUEST_READ_EXTERNAL_STORAGE);
return;
}
}
try {
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(getIntent, getString(R.string.select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, REQUEST_PICK_IMAGE);
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Check Permissions
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.INTERNET},10);
}
}
}
示例4: onRequestPermissionsResult
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case 0:
// disable speech button is permission not granted or instantiate recorder
if (grantResults.length > 0 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
mRecordButton.setEnabled(false);
} else {
mSpeechRecorder = new SpeechRecorder(mConversation);
}
break;
default:
break;
}
}
示例5: startAuth
@TargetApi(23)
public void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) {
CancellationSignal cancellationSignal = new CancellationSignal();
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
return;
}
manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
}
示例6: notifyAlreadyHasPermissions
private static void notifyAlreadyHasPermissions(Object object,
int requestCode,
@NonNull String[] perms) {
int[] grantResults = new int[perms.length];
for (int i = 0; i < perms.length; i++) {
grantResults[i] = PackageManager.PERMISSION_GRANTED;
}
onRequestPermissionsResult(requestCode, perms, grantResults, object);
}
示例7: onClick
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
goScanner();
} else {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, REQUEST_PERMISION_CODE_CAMARE);
}
}
示例8: checkPermissions
/**Checks for the WRITE permission on the external storage. If not present it asks for it*/
private void checkPermissions() {
int canRead = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if(canRead != PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_WRITE);
}
示例9: hasPermission
public boolean hasPermission(String permission)
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
int result = activity.checkSelfPermission(permission);
return PackageManager.PERMISSION_GRANTED == result;
}
else
{
return true;
}
}
示例10: initLocation
private void initLocation() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
List<String> providers = mLocationManager.getProviders(true);
String locationProvider;
/**
* 如果首选GPS定位,会存在这种情况,上次GPS启动采集数据在A地,本次在B地需要定位,但用户恰好在室内无
* GPS信号,只好使用上次定位数据,就出现了地区级偏差。而网络定位则更具有实时性,在精度要求不高以及室内
* 使用场景更多的前提下,首选网络定位
*/
if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
locationProvider = LocationManager.NETWORK_PROVIDER; // 首选网络定位
} else if (providers.contains(LocationManager.GPS_PROVIDER)) {
locationProvider = LocationManager.GPS_PROVIDER;
} else {
locationProvider = LocationManager.PASSIVE_PROVIDER;
}
if (mLocationListener != null)
mLocationManager.requestLocationUpdates(locationProvider, 2000, 10, mLocationListener);
}
示例11: onRequestPermissionsResult
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_PERMISSIONS:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission Granted
selectPicture();
} else {
// Permission Denied
showMessageOKCancel("You need to allow access to SD card to select images.",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
goToSettings();
}
});
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
示例12: onRequestPermissionsResult
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
fillFileList();
}
else {
Toast.makeText(this, R.string.error_070, Toast.LENGTH_LONG).show();
finish();
}
}
示例13: onRequestPermissionsResult
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d(getString(R.string.app_name), "Permission granted. Files can be saved");
} else {
Log.e(getString(R.string.app_name), "Permission denied. The App won\'t work");
finish();
}
break;
}
}
示例14: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery);
if (savedInstanceState == null) {
Intent intent = getIntent();
config = intent.getParcelableExtra(GALLERY_CONFIG);
} else {
config = savedInstanceState.getParcelable(GALLERY_CONFIG);
}
Gallery.init(getApplication());
FrameLayout mian = (FrameLayout) findViewById(R.id.mian);
actionBarLayout = new ActionBarLayout(this);
mian.addView(actionBarLayout);
actionBarLayout.init(mainFragmentsStack);
actionBarLayout.setDelegate(this);
String READ_EXTERNAL_STORAGE = "android.permission.READ_EXTERNAL_STORAGE";
if (checkCallingOrSelfPermission(
READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= 23) {
requestPermissions(new String[]{
READ_EXTERNAL_STORAGE
}, 1);
return;
}
}
showContent(config);
}
示例15: onRequestPermissionsResult
/**
* Handle request permissions result. Update what is needed and give a feedback to the user.
*
* @param requestCode Code of the request.
* @param permissions Requested permissions.
* @param grantResults Result of the request.
*/
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults)
{
switch (requestCode) {
case PERMISSION_REQUEST_CODE_FINE_LOCATION:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), R.string.toast_start_challenge,Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), R.string.toast_start_challenge_denied,
Toast.LENGTH_LONG).show();
}
break;
}
}