Android: Not able to select image from gallery - android

I am trying to pick a picture from the gallery and set it as a background for the view. Now, I am able to select pics as long as they are on my SD card. But as my gallery is in sync with my picasa album and when I try to select one of those pics, the cursor is returning NULL. Below is my code.
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
The selected image has URI of "
https://lh5.googleusercontent.com/-thIdOA38IO0/SY8GG8PqW4I/AAAAAAAABKA/f3XpPvY9JHo/s1024/Picture%252520007.jpg"
Can someone help?
Thx!
Rahul.

Uri selectedImage = Uri.parse(imageReturnedIntent.getDataString());
Try the above line which return the Uri of selectedImage.

Related

Importing images into DataBase

in my app I use SqLite Database "Templates", where I have table "favourites", constains of four columns "id", "description", "imagePath", "category". I would like user to be able use their own images in my app, like this:
When user click button, he choose image from gallery, write description and choose category of image. I know I need use Content Values to do this. But how can I do my table has imagePathes, i.e how can I show them later using RecyclerView and Picasso?
You can load image from device memory:
Picasso.get().load(new File("path-to-you-image/image.png")).into(imageView);
If you are asking "how to get image path" - you can get it in the onActivityResult method:
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();

android return all selected images path

good day. I am hoping that anyone can answer this. I will be straight to my question.
How can I get ALL the image location of the selected images from image gallery?
For example if I select three images on the gallery, it should output me like this.
[/storage/extSdCard/DCIM/Camera/image1.jpg, /storage/extSdCard/DCIM/Camera/image2.jpg, /storage/extSdCard/DCIM/Camera/image3.jpg]
This is my code to laod the Image Gallery
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 5);
and this is my code to get the image link
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
imgPath = cursor.getString(columnIndex);
Log.i("Path : ",imgPath);
and this is my log
11254-11254/com.example.com I/Path : /storage/extSdCard/DCIM/Camera/20170104_171334.jpg
As you can see only one were return, even I have been selected 3 items
IMHO Why you don't using RESTful? If you will use JSON + Retrofit, it will be easy way to add something new client-server api, isn't it?

Set last taken image automatically form gallery in image view

please check image hereI need to set last taken image form gallery in image view or on Image button automatically just like used in default camera ,some body help me to sort out this problem
We can get the last taken image from MediaStore,
String[] proj = new String[]{
MediaStore.Images.ImageColumns.DATA,
};
final Cursor cursor = getContentResolver()
.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, null,
null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
if (cursor.moveToFirst()) {
String lastImageLocation = cursor.getString(0);
}

How to change file URI string

How to change something file:///system/media/lockscreen/lockscreen_001.jpg to
something like /mnt/sdcard/myPicture.jpg
The reason why I want to change is that file:/// is wrong if I want to further process. It is hard to tell but if I get the URI from Uri uri= data.getData(); is file:///system/media/lockscreen/lockscreen_001.jpg, how to handle because normally is start with mnt
Try this :
Uri uri = Uri.parse("file:///system/media/lockscreen/lockscreen_001.jpg");
Toast.makeText(getApplicationContext(), ""+uri.getPath(), Toast.LENGTH_LONG).show();
uri.getPath() will give you the path by eliminating file: extension.
EDIT :
Uri urinew = Uri.parse(uri.getPath());
This will give you new uri with the path you got.
Hope it helps you.
Thanks.
Hope this code can help you :
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);

How to send image through bluetooth in android?

In my application, I open my gallery and pick a picture and then show my image in an image view then I'm supposed to send it through bluetooth.
That's what i've reached :
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
iv.setImageBitmap(yourSelectedImage);
How to send it through bluetooth?
N.B I've opened my bluetooth and made it also discover-able by other devices .
Please I'll be thankful if u helped me in my assignment =]

Categories

Resources