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


Java Activity.requestPermissions方法代碼示例

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


在下文中一共展示了Activity.requestPermissions方法的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: getLocation

import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.M)
public static void getLocation(final Activity mActivity, final int PERMISSION_REQUEST_CODE)
{
        List<String> permissionsNeeded = new ArrayList<>();

        List<String> permissionsList = new ArrayList<>();

        if (!addPermission(mActivity,permissionsList, android.Manifest.permission.ACCESS_FINE_LOCATION))
            permissionsNeeded.add(mActivity.getResources().getString(R.string.GPS));


        if (permissionsList.size() > 0)
        {
            mActivity.requestPermissions(permissionsList.toArray(new String[permissionsList.size()]), PERMISSION_REQUEST_CODE);
        }
}
 
開發者ID:yash786agg,項目名稱:GPS,代碼行數:17,代碼來源:AcessLocation.java

示例3: getOTP

import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.M)
static void getOTP(final Activity mActivity, final int PERMISSION_REQUEST_CODE)
{
    List<String> permissionsNeeded = new ArrayList<>();

    List<String> permissionsList = new ArrayList<>();

    if (!addPermission(mActivity,permissionsList, android.Manifest.permission.READ_SMS))
        permissionsNeeded.add(mActivity.getResources().getString(R.string.READ_SMS));


    if (permissionsList.size() > 0)
    {
        mActivity.requestPermissions(permissionsList.toArray(new String[permissionsList.size()]), PERMISSION_REQUEST_CODE);
    }
}
 
開發者ID:yash786agg,項目名稱:Read_SMS,代碼行數:17,代碼來源:Acess_SMS.java

示例4: 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

示例5: askForPermission

import android.app.Activity; //導入方法依賴的package包/類
public static void askForPermission(Activity activity, String[] permissions, PermissionCallback permissionCallback) {
    if (permissionCallback == null) {
        return;
    }
    if (hasPermission(activity, permissions)) {
        permissionCallback.permissionGranted();
        return;
    }
    PermissionRequest permissionRequest = new PermissionRequest(new ArrayList<String>(Arrays.asList(permissions)), permissionCallback);
    permissionRequests.add(permissionRequest);

    activity.requestPermissions(permissions, permissionRequest.getRequestCode());
}
 
開發者ID:Vinetos,項目名稱:Hello-Music-droid,代碼行數:14,代碼來源:Nammu.java

示例6: requestPermission

import android.app.Activity; //導入方法依賴的package包/類
public static void requestPermission(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.shouldShowRequestPermissionRationale(PERMISSION_CAMERA)
                || activity.shouldShowRequestPermissionRationale(PERMISSION_STORAGE)) {
            Toast.makeText(activity, "Need camera and storage permissions to continue",
                    Toast.LENGTH_LONG).show();
        }
        activity.requestPermissions(new String[]{PERMISSION_CAMERA,
                PERMISSION_STORAGE}, PERMISSIONS_REQUEST);
    }
}
 
開發者ID:deepenai,項目名稱:deepenlib-android-sample,代碼行數:12,代碼來源:PermissionUtil.java

示例7: 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

示例8: 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

示例9: requestPermissionsAgain

import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.M)
public static void requestPermissionsAgain(Activity activity, String[] permissions,
                                           int requestCode) {
    try {
        activity.requestPermissions(permissions, requestCode);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:lennyup,項目名稱:react-native-udesk,代碼行數:10,代碼來源:XPermissionUtils.java

示例10: requestSMSPermission

import android.app.Activity; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.M)
public static void requestSMSPermission(@NonNull Activity activity) {
    final String permission = Manifest.permission.RECEIVE_SMS;
    int hasSpecificPermission = ContextCompat.checkSelfPermission(activity, permission);
    if (hasSpecificPermission != PackageManager.PERMISSION_GRANTED
            && !activity.shouldShowRequestPermissionRationale(permission)) {
        activity.requestPermissions(new String[]{permission},
                REQUEST_CODE_ASK_PERMISSIONS);
    }
}
 
開發者ID:adorsys,項目名稱:sms-parser-android,代碼行數:11,代碼來源:SmsTool.java

示例11: requestPermissions

import android.app.Activity; //導入方法依賴的package包/類
@Nullable
public static HttpResponse requestPermissions(@NonNull String ... permissions) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Activity activity = getCurrentActivity();
        if (activity != null && !checkSelfPermissions(activity, permissions)) {
            activity.requestPermissions(permissions, 0);
            return new HttpResponse(new ErrorPage("This module require additional permissions. Please allow it on your smartphone and reload this page.").toHtml());
        }
    }
    return null;
}
 
開發者ID:bartwell,項目名稱:ultra-debugger,代碼行數:12,代碼來源:CommonUtils.java

示例12: requestContactPermission

import android.app.Activity; //導入方法依賴的package包/類
static void requestContactPermission(Activity activity) {

        activity.requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}
                , CONTACT_REQUEST_CODE);
    }
 
開發者ID:enricocid,項目名稱:EasyOne,代碼行數:6,代碼來源:PermissionUtils.java

示例13: requestWriteStoragePermission

import android.app.Activity; //導入方法依賴的package包/類
public static void requestWriteStoragePermission(Activity activity) {
    if (Utils.hasMarshmallow()) {
        activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                REQUEST_PERMISSION_WRITE_STORAGE);
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:7,代碼來源:AppPerms.java

示例14: requestReadExternalStoragePermission

import android.app.Activity; //導入方法依賴的package包/類
public static void requestReadExternalStoragePermission(Activity activity) {
    if (Utils.hasMarshmallow()) {
        activity.requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                REQUEST_PERMISSION_READ_EXTARNAL_STORAGE);
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:7,代碼來源:AppPerms.java

示例15: requestPermissions

import android.app.Activity; //導入方法依賴的package包/類
public static void requestPermissions(Context context) {
    Activity activity = (Activity) context;
    if (!checkPermissions(context)) {
        activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, AppPreferences.CODE_PERMISSION);
    }
}
 
開發者ID:dkanada,項目名稱:OpenAPK,代碼行數:7,代碼來源:OtherUtils.java


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