android 7.0后访问本地图片的问题和RadioGroup来回切换状态导致状态设置无效

android 7.0后访问本地图片的问题:

解决:用内容提供者进行访问,在清单文件里添加

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="包名.FileProvider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>
定义xml文件 命名为file_paths    
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path
        name="external_storage_root"
        path="." />
</paths>


/**
 * 拍照按钮事件
 */
public void onPhotographClick(View arg0) {
   boolean isPermisson = PermissionUtils.checkPermissionAllGranted(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,}, mContext);
   if (isPermisson){
      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
      try {
         // 指定存放拍摄照片的位置
         File f = createImageFile();
         Uri mOriginUri;
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {  //判断版本是否大于7.0
            mOriginUri = FileProvider.getUriForFile(this.getApplication(), this.getApplication().getPackageName() + ".FileProvider", f);
         } else {
            mOriginUri = Uri.fromFile(f);
         }
         takePictureIntent.putExtra("output", mOriginUri);
         startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);

      } catch (IOException e) {
         e.printStackTrace();
      }
   }else{
      ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},MY_PERMISSION_REQUEST_CODE);
   }

}

private File createImageFile() throws IOException {

   SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
   String timeStamp = format.format(new Date());
   String imageFileName = "activity_" + timeStamp + ".jpg";

   File image = new File(PictureUtil.getAlbumDir(), imageFileName);
//mCurrentPhotoPath = image.getAbsolutePath();
//list.add(mCurrentPhotoPath);
//LogUtils.e("Photo",list.get(0)); return image;}

/**
 * 获取保存图片的目录
 * 
 * @return
 */
public static File getAlbumDir() {
   File dir = new File(
         Environment
               .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
         getAlbumName());
   if (!dir.exists()) {
      dir.mkdirs();
   }
   return dir;
}

/**
 * 获取保存 隐患检查的图片文件夹名称
 * 
 * @return
 */
public static String getAlbumName() {
   return "activity";
}

RadioGroup来回切换状态导致状态设置无效

解决:在设置RadioGroup里的子view 的setcheck的方法之前调用   RadioGroup.clearcheck方法。

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页