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


Java Activity.checkSelfPermission方法代碼示例

本文整理匯總了Java中android.app.Activity.checkSelfPermission方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.checkSelfPermission方法的具體用法?Java Activity.checkSelfPermission怎麽用?Java Activity.checkSelfPermission使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.Activity的用法示例。


在下文中一共展示了Activity.checkSelfPermission方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: askForPermissons

import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons() {
    Activity activity = getParentActivity();
    if (activity == null) {
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        permissons.add(Manifest.permission.READ_CONTACTS);
        permissons.add(Manifest.permission.WRITE_CONTACTS);
        permissons.add(Manifest.permission.GET_ACCOUNTS);
    }
    if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        permissons.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        permissons.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    String[] items = permissons.toArray(new String[permissons.size()]);
    activity.requestPermissions(items, 1);
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:20,代碼來源:DialogsActivity.java

示例2: getPermission

import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(M)
static private void getPermission(String[] permissions,Activity activity) {
    if(Build.VERSION.SDK_INT>=23) {
        ArrayList<String> preToDo = new ArrayList<>();
        boolean tip = false;
        for (String pre : permissions) {
            if (activity.checkSelfPermission(pre) != PackageManager.PERMISSION_GRANTED) {
                preToDo.add(pre);
                if (activity.shouldShowRequestPermissionRationale(pre)) {
                    tip = true;
                }
            }
        }
        if (preToDo.size() == 0)
            return;
        if (tip)
            showToast(sContext.getString(R.string.permissions_need));
        activity.requestPermissions(preToDo.toArray(new String[preToDo.size()]), 0);
    }
}
 
開發者ID:XndroidDev,項目名稱:Xndroid,代碼行數:21,代碼來源:LaunchService.java

示例3: validatePermissions

import android.app.Activity; //導入方法依賴的package包/類
public static boolean validatePermissions(final Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            return true;
        } else {
            AlertDialog.Builder alert = new AlertDialog.Builder(activity);
            alert.setTitle("Permission Error");
            alert.setMessage("Grant permissions in the next dialog and retry download.");
            alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                    ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
                }
            });
            alert.show();
            return false;
        }
    } else {
        return true;
    }
}
 
開發者ID:skyguy126,項目名稱:Xposed-SoundCloudDownloader,代碼行數:22,代碼來源:Shared.java

示例4: isContactsPermissionGranted

import android.app.Activity; //導入方法依賴的package包/類
private static boolean isContactsPermissionGranted(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(READ_CONTACTS)
                == PackageManager.PERMISSION_GRANTED) {
            Timber.d("Permission is granted");
            return true;
        } else {

            Timber.d("Permission is revoked");
            ActivityCompat.requestPermissions(activity,
                    new String[]{READ_CONTACTS},
                    activity.getResources().getInteger(R.integer.contacts_request));
            return false;
        }
    } else { //permission is automatically granted on sdk<23 upon installation
        Timber.d("Permission is granted");
        return true;
    }
}
 
開發者ID:sciage,項目名稱:FinalProject,代碼行數:20,代碼來源:ActivityUtils.java

示例5: maybeRequestReadExternalStoragePermission

import android.app.Activity; //導入方法依賴的package包/類
/**
 * Checks whether it's necessary to request the {@link permission#READ_EXTERNAL_STORAGE}
 * permission read the specified {@link Uri}s, requesting the permission if necessary.
 *
 * @param activity The host activity for checking and requesting the permission.
 * @param uris {@link Uri}s that may require {@link permission#READ_EXTERNAL_STORAGE} to read.
 * @return Whether a permission request was made.
 */
@TargetApi(23)
public static boolean maybeRequestReadExternalStoragePermission(Activity activity, Uri... uris) {
  if (Util.SDK_INT < 23) {
    return false;
  }
  for (Uri uri : uris) {
    if (Util.isLocalFileUri(uri)) {
      if (activity.checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
          != PackageManager.PERMISSION_GRANTED) {
        activity.requestPermissions(new String[] {permission.READ_EXTERNAL_STORAGE}, 0);
        return true;
      }
      break;
    }
  }
  return false;
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:26,代碼來源:Util.java

示例6: isReadStoragePermissionGranted

import android.app.Activity; //導入方法依賴的package包/類
private static boolean isReadStoragePermissionGranted(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Timber.d("Permission is granted");
            return true;
        } else {

            Timber.d("Permission is revoked");
            ActivityCompat.requestPermissions(activity,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    activity.getResources().getInteger(R.integer.read_external_storage_request));
            return false;
        }
    } else { //permission is automatically granted on sdk<23 upon installation
        Timber.d("Permission is granted");
        return true;
    }
}
 
開發者ID:sciage,項目名稱:FinalProject,代碼行數:20,代碼來源:ActivityUtils.java

示例7: findPermissionResult

import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(value = Build.VERSION_CODES.M)
private static List<MPermissionResultEnum> findPermissionResult(Activity activity, String... permissions) {
    boolean overM = isOverMarshmallow();
    List<MPermissionResultEnum> result = new ArrayList<>();
    for (String p : permissions) {
        if (overM) {
            if (activity.checkSelfPermission(p) == PackageManager.PERMISSION_GRANTED) {
                result.add(MPermissionResultEnum.GRANTED);
            } else {
                if (!activity.shouldShowRequestPermissionRationale(p)) {
                    result.add(MPermissionResultEnum.DENIED_NEVER_ASK_AGAIN);
                } else {
                    result.add(MPermissionResultEnum.DENIED);
                }
            }
        } else {
            result.add(MPermissionResultEnum.GRANTED);
        }
    }

    return result;
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:23,代碼來源:BaseMPermission.java

示例8: isAudioPermissionGranted

import android.app.Activity; //導入方法依賴的package包/類
private static boolean isAudioPermissionGranted(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(Manifest.permission.RECORD_AUDIO)
                == PackageManager.PERMISSION_GRANTED) {
            Timber.d("Permission is granted");
            return true;
        } else {

            Timber.d("Permission is revoked");
            ActivityCompat.requestPermissions(activity,
                    new String[]{Manifest.permission.RECORD_AUDIO},
                    activity.getResources().getInteger(R.integer.recorder_request));
            return false;
        }
    } else { //permission is automatically granted on sdk<23 upon installation
        Timber.d("Permission is granted");
        return true;
    }
}
 
開發者ID:sciage,項目名稱:FinalProject,代碼行數:20,代碼來源:ActivityUtils.java

示例9: isWritePermissionGranted

import android.app.Activity; //導入方法依賴的package包/類
private static boolean isWritePermissionGranted(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.checkSelfPermission(WRITE_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Timber.d("Permission is granted");
            return true;
        } else {

            Timber.d("Permission is revoked");
            ActivityCompat.requestPermissions(activity,
                    WRITE_PERM,
                    INT_DELETE_PICTURE_PERM);
            return false;
        }
    } else { //permission is automatically granted on sdk<23 upon installation
        Timber.d("Permission is granted");
        return true;
    }
}
 
開發者ID:sciage,項目名稱:FinalProject,代碼行數:20,代碼來源:ActivityUtils.java

示例10: hasStorageReadPermission

import android.app.Activity; //導入方法依賴的package包/類
private static boolean hasStorageReadPermission(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
                activity.checkSelfPermission(READ_EXTERNAL_STORAGE) == PERMISSION_GRANTED;
    }
    return true;
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:8,代碼來源:PathChecker.java

示例11: getDeniedPermissions

import android.app.Activity; //導入方法依賴的package包/類
/**
 * 獲取請求權限中需要授權的權限
 */
@TargetApi(Build.VERSION_CODES.M)
private static String[] getDeniedPermissions(Activity activity, String[] permissions) {
    List<String> deniedPermissions = new ArrayList();
    try {
        for (String permission : permissions) {
            if (activity.checkSelfPermission(permission) == PackageManager.PERMISSION_DENIED) {
                deniedPermissions.add(permission);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return deniedPermissions.toArray(new String[deniedPermissions.size()]);
}
 
開發者ID:lennyup,項目名稱:react-native-udesk,代碼行數:18,代碼來源:XPermissionUtils.java

示例12: hasPermission

import android.app.Activity; //導入方法依賴的package包/類
/**
 * Returns true if the Activity has access to a all given permission.
 */
public static boolean hasPermission(Activity activity, String[] permissions) {
    for (String permission : permissions) {
        if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
    }
    return true;
}
 
開發者ID:Vinetos,項目名稱:Hello-Music-droid,代碼行數:12,代碼來源:Nammu.java

示例13: checkPermissionManuel

import android.app.Activity; //導入方法依賴的package包/類
public static int checkPermissionManuel(Activity mActivity, String permission, int requestCode){
    int hasWriteContactsPermission = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        hasWriteContactsPermission = mActivity.checkSelfPermission(permission);

    }else{
        hasWriteContactsPermission = 0;
    }
    return hasWriteContactsPermission;
}
 
開發者ID:barisatalay,項目名稱:thermalprinterhelper,代碼行數:11,代碼來源:UtilsPermission.java

示例14: isGrantExternalRW

import android.app.Activity; //導入方法依賴的package包/類
/**
 * 6.0以上權限
 *
 * @param activity
 * @return
 */
public static boolean isGrantExternalRW(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && activity.checkSelfPermission(
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        activity.requestPermissions(new String[]{
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
        }, 1);

        return false;
    }

    return true;
}
 
開發者ID:NICOLITE,項目名稱:HutHelper,代碼行數:21,代碼來源:CommUtil.java

示例15: requestPermission

import android.app.Activity; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.M)
    public static void requestPermission(Activity activity, final String permission,
                                         final int reqCode) {
//        if (checkSelfPermission(Manifest.permission.READ_CONTACTS) !=
//                PackageManager.PERMISSION_GRANTED) {
//
//            requestPermissions(new String[]{Manifest.permission.READ_CONTACTS},
//                    REQUEST_CONTACT_PERMISSION);
//        }
        if (activity.checkSelfPermission(permission) !=
                PackageManager.PERMISSION_GRANTED) {

            activity.requestPermissions(new String[]{permission}, reqCode);
        }
    }
 
開發者ID:shashi2459,項目名稱:notify-me,代碼行數:16,代碼來源:Utils.java


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