gpt4 book ai didi

android 7 中的 android、相机和裁剪图像

转载 作者:行者123 更新时间:2023-11-29 01:03:28 30 4
gpt4 key购买 nike

当我调用 cameraopen(); 时,android 7 中的相机出现强制关闭问题当我从图库中选择图像时,我在裁剪前收到错误消息:“不支持编辑”

应用程序在 android 4.4.2 上运行完美,但在 android 7 上崩溃。为什么?

我不知道该怎么办。请帮助我

我的代码:

 @Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
String languageToLoad = "en"; // your language
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getActivity().getBaseContext().getResources().updateConfiguration(config,
getActivity().getBaseContext().getResources().getDisplayMetrics());
final View view = inflater.inflate(R.layout.ijad_forooshgah, container, false);



int permissionCheck = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA);
//----------------------------------
if(permissionCheck == PackageManager.PERMISSION_DENIED)
RequestRuntimePermission();
return view;


}

private void GalleryOpen() {
GalIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(GalIntent,"Select Image from Gallery"),2);
}
private void CameraOpen() {
CamIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
file = new File(Environment.getExternalStorageDirectory(),
"file"+String.valueOf(System.currentTimeMillis())+".jpg");
uri = Uri.fromFile(file);
CamIntent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
CamIntent.putExtra("return-data",true);
startActivityForResult(CamIntent,0);
}

private void CropImage() {

try{
CropIntent = new Intent("com.android.camera.action.CROP");
CropIntent.setDataAndType(uri,"image/*");

CropIntent.putExtra("crop","true");
CropIntent.putExtra("outputX",180);
CropIntent.putExtra("outputY",180);
CropIntent.putExtra("aspectX",4);
CropIntent.putExtra("aspectY",4);
CropIntent.putExtra("scaleUpIfNeeded",true);
CropIntent.putExtra("return-data",true);

startActivityForResult(CropIntent,1);
}
catch (ActivityNotFoundException ex)
{

}

}`private void RequestRuntimePermission() {
if(ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),Manifest.permission.CAMERA))
Toast.makeText(getActivity(),"CAMERA permission allows us to access CAMERA app",Toast.LENGTH_SHORT).show();
else
{
ActivityCompat.requestPermissions(getActivity(),new String[]{Manifest.permission.CAMERA},RequestPermissionCode);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode)
{
case RequestPermissionCode:
{
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
Toast.makeText(getActivity(),"Permission Granted",Toast.LENGTH_SHORT).show();
else
Toast.makeText(getActivity(),"Permission Canceled",Toast.LENGTH_SHORT).show();
}
break;
}
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.imageToUpload:


AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
ab.setMessage("انتخاب عکس");
ab.setPositiveButton("دوربین", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
CameraOpen();
}
});
ab.setNegativeButton("گالری", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
GalleryOpen();
}
});
ab.show();
break;

}

我需要帮助。谢谢

最佳答案

这个库对你很有用

implementation 'com.yanzhenjie:album:2.1.3'

https://github.com/yanzhenjie/Album

关于android 7 中的 android、相机和裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49260909/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com