i am trying to upload image from gallery and display it on image view but i am getting this error
I/System.out: resolveUri failed on bad bitmap uri: content://media/external/images/media/35
my code:
public void btimage(View view)
{
Intent i = new Intent(
Intent.ACTION_PICK,
MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, 100);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==100 && resultCode==RESULT_OK)
{
Uri uri= data.getData();
imgView.setImageURI(uri);
}
}
try this
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
for
MediaStore.Images.Media.INTERNAL_CONTENT_URI
Related
Set image in com.mikhaellopez.circularimageview.CircularImageView from gallery image display after close android app image not showing in android studio
imgbtnSetProfile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 100);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK && null != data) {
try {
Uri uriImage = data.getData();
circuler_imgView.setImageURI(uriImage);
}
I need to captured an image and display it in Image View
This is what i do;
btnLaunchCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
activeTakePhoto();
}
});
private void activeTakePhoto() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File(Environment.getExternalStorageDirectory(), FILE_NAME);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
startActivityForResult(intent, 119);
}
When i press OK, it takes me the image view, This is what i do to display picture in image view.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
selectedImage = imageUri;
Intent intent= new Intent(CameraLauncherActivity.this, MainActivity.class);
intent.putExtra("imageBitmap", selectedImage);
startActivity(intent);
}
MainActivity
imageUri= (Uri) intentData.getExtras().get("imageBitmap");
mImageView.setImageURI(imageUri);
I am doing a module which needs to convert image into pdf. i have successfully implemented the camera and can display its image. but my problem is getting the uri of that image. i saw a code snippet here in StackOverflow and followed it but it returns null.
here is my sample code:
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
uri = data.getData();
if(uri == null)
{
tvUri.setText("null");
}else{
tvUri.setText(uri.toString());
}
}
}
to test if it is null, i proceeded to set the textview into its value if it has one, but if not, then i set it to null.
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
Uri u = intent.getData();
}
try this
uri = data.getExtras().get("data");
instead of
uri = data.getData();
I've an android application where in an activity the user chooses a picture from the phone's memory to upload it to the server using the Action Pick intent
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
However; now the requirements has changed and the client wants to upload any file with any extension, what intent should I use in order to open the phone's memory (like the file manager) and choose whatever I want?
Now I'm using the Get content intent thanks to you guys:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 1);
but the problem is in the start activity for result
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 1) {
Log.d("select pivture", "passed her");
Uri selectedMediaUri = data.getData();
String Fpath = selectedMediaUri.getPath();
Log.d("Fpath", Fpath);
}
I get as follows:
/document/primary:Download/tool208.pdf
Which is not what I want, I want path like this one:
/external/images/media/6634
Use below method:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
UPDATE
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==PICKFILE_REQUEST_CODE){
}
}
I read an text input from the user, this input i use it as a name of a picture i'm taking by the camera.
i store this name and the path of the image name into Sqlite Database.
what I'm trying to do is, after clicking OK to accept the taken picture, i want the saved path to be displayed in a toast.
the problem is, when I click OK to accept the picture, nothing is being displayed and i cant switch from the camera activity to the activity that called the camera activity"the previous activity"
Note: I'm using the emulator not a real device.
OnClickListener btn_TakePictureListener = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String imgPath = retrievePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri(imgPath));
startActivityForResult(intent, RequestCode);
}
};
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RequestCode && resultCode == RESULT_OK) {
String s = data.getData().toString();
Toast.makeText(getBaseContext(), ""+s, Toast.LENGTH_SHORT).show();
}
}
if you are passing Uri for you image then you can retrieve image as taken by camera:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
Environment.getExternalStorageDirectory(), "temp.jpg")));
startActivityForResult(intent, 1);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == NONE)
return;
if (requestCode == 1) {
// Set the file save path with directory
File picture = new File(Environment.getExternalStorageDirectory()
+ "/temp.jpg");
Uri imageuri= Uri.fromFile(picture);
//set to imageview here
}
}
EDIT:
For Getting data uri in onActivityResult start Camra Activiyt as:
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,IMAGE_UNSPECIFIED);
startActivityForResult(intent, 2);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == NONE)
return;
if (requestCode == 1) {
Uri uriimg = data.getData();
Toast.makeText(getBaseContext(), ""+uriimg.toString(), Toast.LENGTH_SHORT).show();
}
}