當前位置: 首頁>>代碼示例>>Java>>正文


Java PackageManager.PERMISSION_GRANTED屬性代碼示例

本文整理匯總了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();
                }
            }
        }
    }
}
 
開發者ID:hgs1217,項目名稱:Paper-Melody,代碼行數:28,代碼來源:MainActivity.java

示例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();
    }
}
 
開發者ID:tranleduy2000,項目名稱:text_converter,代碼行數:27,代碼來源:BarCodeCodecFragment.java

示例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);
        }
    }
}
 
開發者ID:mezau532,項目名稱:smart_commuter,代碼行數:15,代碼來源:MainActivity.java

示例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;
    }
}
 
開發者ID:pullstring,項目名稱:pullstring-android,代碼行數:15,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:8,代碼來源:FingerprintHandler.java

示例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);
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:10,代碼來源:EasyPermissions.java

示例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);
    }
}
 
開發者ID:MRYangY,項目名稱:YZxing,代碼行數:8,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:bamless,項目名稱:chromium-swe-updater,代碼行數:7,代碼來源:MainActivity.java

示例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;
    }
}
 
開發者ID:jie-meng,項目名稱:DinningShare,代碼行數:12,代碼來源:CordovaInterfaceImpl.java

示例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);
}
 
開發者ID:woxingxiao,項目名稱:GracefulMovies,代碼行數:27,代碼來源:LocationService.java

示例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);

    }
}
 
開發者ID:HitRoxxx,項目名稱:FloatingNew,代碼行數:29,代碼來源:FeedbackActivity.java

示例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();
    }
}
 
開發者ID:mkeresztes,項目名稱:AndiCar,代碼行數:11,代碼來源:FileListActivity.java

示例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;
    }
}
 
開發者ID:SiniTurk,項目名稱:OTAUpdates,代碼行數:13,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:chengzichen,項目名稱:KrGallery,代碼行數:28,代碼來源:GalleryActivity.java

示例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;
    }
}
 
開發者ID:IrrilevantHappyLlamas,項目名稱:Runnest,代碼行數:23,代碼來源:ChallengeActivity.java


注:本文中的android.content.pm.PackageManager.PERMISSION_GRANTED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。