当前位置: 首页>>代码示例>>Java>>正文


Java ContextCompat.checkSelfPermission方法代码示例

本文整理汇总了Java中android.support.v4.content.ContextCompat.checkSelfPermission方法的典型用法代码示例。如果您正苦于以下问题:Java ContextCompat.checkSelfPermission方法的具体用法?Java ContextCompat.checkSelfPermission怎么用?Java ContextCompat.checkSelfPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.content.ContextCompat的用法示例。


在下文中一共展示了ContextCompat.checkSelfPermission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requestRuntimePermission

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public static void requestRuntimePermission(Activity activity, String[] permissions,
                                            OnRequestPermissionsListener listener) {
    Activity topActivity = activity;
    if (null == topActivity) {
        return;
    }
    mListener = listener;
    List<String> permissionList = new ArrayList<>();
    for (String permission : permissions) {
        if (ContextCompat.checkSelfPermission(topActivity, permission)
                != PackageManager.PERMISSION_GRANTED) {

            permissionList.add(permission);
        }
    }
    if (!permissionList.isEmpty()) {
        ActivityCompat.requestPermissions(topActivity,
                permissionList.toArray(new String[permissionList.size()]),
                PERMISSION_REQUEST_CODE);
    } else {
        mListener.onGranted();
    }
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:24,代码来源:RequestPermissions.java

示例2: takePhoto

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
 * 拍照
 */
private void takePhoto() {
    //在每次拍照做权限的判断,防止出现权限不全而获取不到图像
    if (ContextCompat.checkSelfPermission(activity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
            || ContextCompat.checkSelfPermission(activity,
            Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    Intent takeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
        photoUri = get24MediaFileUri(TYPE_TAKE_PHOTO);
        takeIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }else {
        photoUri = getMediaFileUri(TYPE_TAKE_PHOTO);
    }
    takeIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
    activity.startActivityForResult(takeIntent, CODE_TAKE_PHOTO);
}
 
开发者ID:funnyzhaov,项目名称:Tribe,代码行数:23,代码来源:DraggablePresenterImpl.java

示例3: getPermission

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private void getPermission() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    } else {
    }
}
 
开发者ID:Team-Sprout,项目名称:Clipcon-AndroidClient,代码行数:22,代码来源:TransparentActivity.java

示例4: connectToBluetooth

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
 * connect to the bluetooth
 *
 * @param deviceInfo
 */
private void connectToBluetooth(final DeviceInfoBean deviceInfo) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            switch (ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.ACCESS_COARSE_LOCATION)) {
                case PackageManager.PERMISSION_DENIED:
                    performPermissionDeniedAction(deviceInfo);
                    break;
                case PackageManager.PERMISSION_GRANTED:
                    startDeviceConnection(deviceInfo, healthCareReceiver);
                    break;
                default:
                    break;
            }
        } else {
            startDeviceConnection(deviceInfo, healthCareReceiver);
        }

    } catch (RuntimeException e) {
        showToastMessage(e.getMessage(), mContext);
        Log.e(AppUtility.TAG, Log.getStackTraceString(e));
    }

}
 
开发者ID:Welloculus,项目名称:MobileAppForPatient,代码行数:29,代码来源:AllDeviceListActivity.java

示例5: onCreate

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

if (!SharedPreferenceHelper.getToken().isEmpty()) {
	Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
	startActivity(intent);
	finish();
} else {
	setContentView(R.layout.activity_register);
	ButterKnife.bind(this);

	FormatWatcher formatWatcher = new MaskFormatWatcher(
			MaskImpl.createTerminated(PredefinedSlots.RUS_PHONE_NUMBER) // маска для серии и номера
	);
	formatWatcher.installOn(phoneEditText);

	if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
		ActivityCompat.requestPermissions(this,
				new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);
	}
}
  }
 
开发者ID:Svyatozar,项目名称:Navalny.Pulse,代码行数:24,代码来源:RegisterActivity.java

示例6: permissionsRequest

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public void permissionsRequest() {

        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.INTERNET)
                != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED ||ContextCompat.checkSelfPermission(this,
                Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.INTERNET, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 111);

        }
    }
 
开发者ID:arpit999,项目名称:KudanVRDemo,代码行数:17,代码来源:MainActivity.java

示例7: downloadVideo

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public static long downloadVideo(Context context, String url) {
    if (ContextCompat.checkSelfPermission(context,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        EventBus.getDefault().post(new EventPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE));
        return -1;
    }
    DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    if (url != null) {
        Uri uri = Uri.parse(url);
        DownloadManager.Request request = new DownloadManager.Request(uri);
        File dst = FileUtils.createVideoFile(uri);
        if (dst.exists()) {
            Toast.makeText(context, R.string.video_exist, Toast.LENGTH_SHORT).show();
        } else {
            request.setDestinationUri(Uri.fromFile(dst));
            request.allowScanningByMediaScanner();
            long id = manager.enqueue(request);
            Log.d("download id", "-->" + id);
            return id;
        }
    }
    return -1;
}
 
开发者ID:mingdroid,项目名称:tumbviewer,代码行数:24,代码来源:SystemDownload.java

示例8: onCreate

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splashscreen_main);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    //marshmallow check permission permissions
    boolean hasPermission = (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
    if (!hasPermission) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                REQUEST_WRITE_STORAGE);
    } else {
        validateFilesAndDownload();
    }

}
 
开发者ID:fekracomputers,项目名称:QuranAndroid,代码行数:22,代码来源:MainActivity.java

示例9: checkStorageAccess

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private boolean checkStorageAccess(boolean yay) {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                yay? REQUEST_READ_EXTERNAL_STORAGE : REQUEST_READ_EXTERNAL_STORAGE_NOYAY);
        return false;
    }
    return true;
}
 
开发者ID:quaap,项目名称:BookyMcBookface,代码行数:10,代码来源:BookListActivity.java

示例10: hasAudioRecordPermissions

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private boolean hasAudioRecordPermissions() {
    final Context app = getApplicationContext();

    int recordPermission = ContextCompat.checkSelfPermission(app, Manifest.permission.RECORD_AUDIO);
    int writePermission = ContextCompat.checkSelfPermission(app, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    return recordPermission == PackageManager.PERMISSION_GRANTED && writePermission == PackageManager.PERMISSION_GRANTED;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:8,代码来源:ChatPrensenter.java

示例11: onCreate

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mLocationClient = new LocationClient(getApplicationContext());
    mLocationClient.registerLocationListener(new MyLocationListener());
    SDKInitializer.initialize(getApplicationContext());
    setContentView(R.layout.activity_main);
    mapView = (MapView) findViewById(R.id.bmapView);
    baiduMap = mapView.getMap();
    baiduMap.setMyLocationEnabled(true);
    positionText = (TextView) findViewById(R.id.position_text_view);
    List<String> permissionList = new ArrayList<>();
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
        permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
    }

    if (ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED){
        permissionList.add(Manifest.permission.READ_PHONE_STATE);
    }

    if (ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
        permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }

    if (!permissionList.isEmpty()){
        String [] permissions = permissionList.toArray(new String[permissionList.size()]);
        ActivityCompat.requestPermissions(MainActivity.this,permissions,1);
    }else {
        requestLocation();
    }
}
 
开发者ID:wangyufei1006,项目名称:LBSTest,代码行数:32,代码来源:MainActivity.java

示例12: start

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
 * 用于启动扫码的Activity,启动之前要做权限判断。
 */
@LuaViewApi
public void start() {
    if (ContextCompat.checkSelfPermission(mActivity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {//还没有授予权限
        if (ActivityCompat.shouldShowRequestPermissionRationale(mActivity, Manifest.permission.CAMERA)) {
            Toast.makeText(mActivity, "Please Allow the Camera permission.", Toast.LENGTH_SHORT).show();
        } else {
            ActivityCompat.requestPermissions(mActivity, new String[]{Manifest.permission.CAMERA}, MainActivity.REQUEST_CAMERA);
        }
    } else {
        mActivity.startActivityForResult(new Intent(mActivity , CaptureActivity.class) , 0);
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:16,代码来源:ScanBridge.java

示例13: ensureExternalStoragePermissionGranted

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private boolean ensureExternalStoragePermissionGranted() {
  if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE)
      != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(
        getActivity(),
        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
        PERMISSION_REQUEST_READ_EXTERNAL_STORAGE);
    return false;
  }
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:DraweeMediaPickerFragment.java

示例14: notHasPermission

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private String[] notHasPermission(Context context, String[] permissions) {
    ArrayList<String> notPermissions = new ArrayList<>();
    for (String permission : permissions) {
        try {
            if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
                notPermissions.add(permission);
            }
        } catch (Throwable t) {
            Log.e(String.format("Failure checking permission %s", permission), t.getMessage());
        }
    }
    return notPermissions.toArray(new String[]{});
}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:14,代码来源:SinglePermission.java

示例15: setupLocationClient

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public void setupLocationClient(Context context) {
    if(locationClient == null) {
        if(ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            locationClient = LocationServices.getFusedLocationProviderClient(context);
        }
    }
}
 
开发者ID:jpelgrom,项目名称:Movie-Notifier-Android,代码行数:8,代码来源:LocationUtil.java


注:本文中的android.support.v4.content.ContextCompat.checkSelfPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。