i have a force close problem with camera in android 7 when i call cameraopen();
and when i picking an image from gallery i get error before cropping : "Editing is not supported"
app working perfectly on android 4.4.2 but on android 7 crashing.why?
i don't know what to do. please help me
my codes:
@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;
} }
i need help. thank you