| | |
| | | import android.os.Environment; |
| | | import android.provider.DocumentsContract; |
| | | import android.provider.MediaStore; |
| | | import android.provider.Settings; |
| | | import android.text.TextUtils; |
| | | import android.view.LayoutInflater; |
| | | import android.view.MotionEvent; |
| | |
| | | import android.widget.PopupWindow; |
| | | import android.widget.RelativeLayout; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.core.content.FileProvider; |
| | | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.other.HdlDialogLogic; |
| | |
| | | * 拍照获取图片 |
| | | **/ |
| | | private void take_photo() { |
| | | //获取系統版本 |
| | | int currentapiVersion = Build.VERSION.SDK_INT; |
| | | // 激活相机 |
| | | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| | | // 判断存储卡是否可以用,可用进行存储 |
| | | SimpleDateFormat timeStampFormat = new SimpleDateFormat( |
| | | "yyyy_MM_dd_HH_mm_ss", Locale.ENGLISH); |
| | | String filename = timeStampFormat.format(new Date()); |
| | | outputImagepath = new File(hdl_Dir, |
| | | filename + ".jpg"); |
| | | if (currentapiVersion < 24) { |
| | | // 从文件中创建uri |
| | | Uri uri = Uri.fromFile(outputImagepath); |
| | | intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); |
| | | } else { |
| | | try { |
| | | //获取系統版本 |
| | | int currentapiVersion = Build.VERSION.SDK_INT; |
| | | // 激活相机 |
| | | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| | | // 判断存储卡是否可以用,可用进行存储 |
| | | SimpleDateFormat timeStampFormat = new SimpleDateFormat( |
| | | "yyyy_MM_dd_HH_mm_ss", Locale.ENGLISH); |
| | | String filename = timeStampFormat.format(new Date()); |
| | | outputImagepath = new File(hdl_Dir, |
| | | filename + ".jpg"); |
| | | if (currentapiVersion < 24) { |
| | | // 从文件中创建uri |
| | | Uri uri = Uri.fromFile(outputImagepath); |
| | | intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); |
| | | } else { |
| | | // //兼容android7.0 使用共享文件的形式 |
| | | // ContentValues contentValues = new ContentValues(1); |
| | | // contentValues.put(MediaStore.Images.Media.DATA, outputImagepath.getAbsolutePath()); |
| | | // Uri uri = mContext.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues); |
| | | // intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); |
| | | // Uri photoURI = FileProvider.getUriForFile(mContext, "com.hdl.photovoltaic.dc.fileprovider", outputImagepath); |
| | | // intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| | | // intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); |
| | | |
| | | //兼容android7.0 使用共享文件的形式 |
| | | ContentValues contentValues = new ContentValues(1); |
| | | contentValues.put(MediaStore.Images.Media.DATA, outputImagepath.getAbsolutePath()); |
| | | contentValues.put(MediaStore.Images.Media.DISPLAY_NAME, outputImagepath.getName()); |
| | | contentValues.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); |
| | | Uri uri = mContext.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues); |
| | | intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); |
| | | // Uri photoURI= FileProvider.getUriForFile(mContext,"com.hdl.debugtreasure.dc.fileprovider",outputImagepath); |
| | | // intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| | | // intent.putExtra(MediaStore.EXTRA_OUTPUT,photoURI); |
| | | Uri photoURI = FileProvider.getUriForFile(mContext, "com.hdl.photovoltaic.fileProvider", outputImagepath); |
| | | intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| | | intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); |
| | | } |
| | | // 开启一个带有返回值的Activity,请求码为PHOTO_REQUEST_CAREMA |
| | | ((Activity) mContext).startActivityForResult(intent, TAKE_PHOTO); |
| | | } catch (Exception e) { |
| | | HdlThreadLogic.toast(mContext, R.string.loading_not_supported); |
| | | } |
| | | // 开启一个带有返回值的Activity,请求码为PHOTO_REQUEST_CAREMA |
| | | ((Activity) mContext).startActivityForResult(intent, TAKE_PHOTO); |
| | | |
| | | } |
| | | |
| | |
| | | HdlThreadLogic.toast(mContext, R.string.camera_album_file_save_fial); |
| | | } else { |
| | | if (!TextUtils.isEmpty(outputImagepath.getAbsolutePath())) { |
| | | //注意:(android13,14需要再设置-隐私-)特殊权限设置 |
| | | orc_bitmap = BitmapFactory.decodeFile(outputImagepath.getAbsolutePath());//获取图片 |
| | | saveBitmap(comp(ImgUpdateDirection(outputImagepath.getAbsolutePath()))); //压缩图片 |
| | | } else { |
| | | HdlThreadLogic.toast(mContext, R.string.camera_album_file_get_fial); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | public interface CameraAlbumListener { |
| | | void successCallBack(File a); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |