Weird camera issue on samsung S4 - java

I have an app where I am using Camera intent to capture image and use it for further purpose, problem is on every phone i tested it works (nexus 6p,HTC One m8,S5,redmi 1s) but on S4 the camera goes portrait always and after capturing image returns nothing. Below is the code i m using
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE_OWNER);
}
And to get the image captured , using following simple code
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE_OWNER && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
CircularImageView circularImageView = (CircularImageView)findViewById(R.id.imgViewParking);
circularImageView.setImageBitmap(imageBitmap);
mOwnerImage = imageBitmap;
}
}
Not sure what is wrong with samsung S4 camera software , how to solve it ?

Related

Upload your own profile picture

When I start the application, I upload an image using Picasso to imageview. I'm trying to make the user upload their own image. If I take a picture or select it from the gallery, I can display it in an imageview. But I would like to use SharedPreferences to display the image the next time I load the application, which I unfortunately can't do.
Here is my code.
private void showImageOptionDialog(){
final String[] options = getResources().getStringArray(R.array.image_options);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(R.string.alert_dialog_title)
.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case 0:
Intent cameraIntent = new Intent();
cameraIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 11);
break;
case 1:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 9);
break;
case 2:
SaveSharedPreference.setAvatar(context, "none");
recreate();
break;
}
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//Check if the intent was to pick image, was successful and an image was picked
if(requestCode == 9 && resultCode == RESULT_OK && data != null){
//Get selected image uri from phone gallery
Uri selectedImage = data.getData();
//Display selected photo in image view
//head_image.setImageURI(selectedImage);
assert selectedImage != null;
SaveSharedPreference.setAvatar(context, selectedImage.toString());
}
//Handle camera request
else if(requestCode == 11 && resultCode == RESULT_OK && data != null){
//We need a bitmap variable to store the photo
Bitmap bitmap = (Bitmap) Objects.requireNonNull(data.getExtras()).get("data");
//Display taken picture in image view
head_image.setImageBitmap(bitmap);
}
recreate();
}
Then I try to load using
Picasso.get()
.load(SaveSharedPreference.getAvatar(context))
.placeholder(R.mipmap.ic_launcher)
.transform(new CropCircleTransformation())
.into(head_image);
Thank you for your help
(application runs on Android 7.0+)
It's NOT a good idea to save a photo using SharedPreferences. Try caching it or use a local Database or File system to store and/or restore them

Take picture without saving it

I want to call the android's native camera and don't save it in the storage, because I save it myself after processing image. It works almost for all devices, except Motorola XT1032 (Android 5.1, API 22). So is there a way to tell the camera not to save the picture?
Here is how I call the camera intent.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.separator + "image_"+System.currentTimeMillis()+".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
((Activity) mContext).startActivityForResult(intent, 1001);
Create the request code variable:
private static final int REQUEST_CAMERA = 1;
Open the camera:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
and in case you want to show it to the user:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CAMERA:
if (resultCode == RESULT_OK) {
// successfully captured the image
Bitmap mBitmap = (Bitmap) data.getExtras().get("data");
if (mBitmap != null) {
imageView.setImageBitmap(mBitmap);
}
}
}

How can i make sure the image is not saved to gallery?

I'm making an app that will let users password-protect photos. So far, the user can take a photo and the photo gets displayed. However, all the photos get saved to camera roll. How can I save them to the app instead of camera roll so they can be private, but still be able to access them from their uri (which I will save to SharedPreferences) ?
int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 0;
Uri imageUri;
public void takePic(View view){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "filename_" +
String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra("data", imageUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
Bundle extras = data.getExtras();
Log.e("URI", imageUri.toString());
Bitmap bmp = (Bitmap) extras.get("data");
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(bmp);
}
else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
}
}
}
create a file named (.nomedia) in the folder, then all the photos in this folder will not be shown!
OR
Save your photos on Internal storage.

Capture image and transfer it to another activity

I need help.
I have a project like Meme Generator, I have two Activities.
Activity_main (User Interface and has a button to trigger "choose camera option"
and Creatememe(as Second Activity to show the captured image from Activity_main).
Now my Problem is, When I'm using Android Version 4.0.4 to lower versions The image is passing through the Second Activity.
while using Android version higher that 4.0.4 the Image didn't pass to Second Activity, The image only shows inside Activity_main.
preview.setImageBitmap(bitmap) //<- shows image inside Activity_main.
Here are my codes for AndroidManifest file
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera"/>
Then here is my code for Activity_main
try {
InputStream input = getContentResolver().openInputStream(selectedImageUri);
final Bitmap bitmap = BitmapFactory.decodeStream(input);
preview.setImageBitmap(bitmap);
preview.setDrawingCacheEnabled(true);
Bitmap b= preview.getDrawingCache();
Intent i = new Intent(this, CreateMeme.class);
i.putExtra("Bitmap", b);
startActivity(i);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Then here's my code for Second Activity
imageView = (ImageView) findViewById(R.id.imageView2);
Intent intent = getIntent();
Bitmap bitmap = intent.getParcelableExtra("Bitmap");
imageView.setImageBitmap(bitmap);
on the OnClickListener of "choose camera option" use the next method
static final int REQUEST_IMAGE_CAPTURE = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
Then,override OnActivityResult and handle the result like this
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Intent intent = new Intent(MainActivity.this,CreateMeme.class);
intent.putExtras(extras);
startActivity(intent);
}
}
On your CreateMeme.class handle the extras like that -
imageView = (ImageView) findViewById(R.id.imageView2);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
imageView.setImageBitmap(bitmap);
For more information, Refer this link

Get Actual Image from onActivityResult and not Thumbnail Android Java

I am using onActivityResult to get an image taken from the camera intent. I would like to get the actual image and not the thumbnail. How can I do that. When I use data.getExtras().get("data") I get the thumbnail which is low quality. I do not wish to save the image locally as I will be uploading it to a server.
Camera Intent:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
onActivityResult:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
}
}
How can I do that
Provide a Uri in EXTRA_OUTPUT in your Intent, pointing to a location where the third-party camera app can write the image.
I do not wish to save the image locally as I will be uploading it to a server.
Then either settle for the thumbnail or write your own camera code (rather than using a third-party app).

Categories

Resources