android 8.0动态申请读写权限

获取读写权限

	 public void checkPermission() {
	        boolean isGranted = true;
	        if (android.os.Build.VERSION.SDK_INT >= 23) {
	            if (mCPContext.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
	                //如果没有写sd卡权限
	                isGranted = false;
	            }
	            if (mCPContext.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
	                isGranted = false;
	            }
	            Log.i("cbs","isGranted == "+isGranted);
	            if (!isGranted) {
	            	((Activity) mCPContext).requestPermissions(
	                        new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission
	                                .ACCESS_FINE_LOCATION,
	                                Manifest.permission.READ_EXTERNAL_STORAGE,
	                                Manifest.permission.WRITE_EXTERNAL_STORAGE},
	                        102);
	            }
	        }
	    
	}

 获取安装未知来源权限

	/** 
	 * 判断是否是8.0系统,是的话需要获取此权限,判断开没开,没开的话处理未知应用来源权限问题,否则直接安装 
	*/
	private void checkIsAndroidO()
	{
		if (android.os.Build.VERSION.SDK_INT >= 26)
		{
			boolean b =this.getPackageManager().canRequestPackageInstalls();
			if(b)
			{
				//publicApk();//安装应用的逻辑(写自己的就可以)  
			}
			else
			{//请求安装未知应用来源的权限
				this.requestPermissions(new String[]{Manifest.permission.REQUEST_INSTALL_PACKAGES},102);
			}
		}else
		{
			//publicApk();
		}
	}

 

你可能感兴趣的:(android 8.0动态申请读写权限)