本文整理匯總了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;
}
}