Select multiple image from album and store in bitmap array Android - android

I have tried to modify on able to select multiple photo in album but the result just allowed me to select single photo. And I want to know that is it possible to store the selected multiple photo into Bitmap array so that I can call a function like save Image with using the bitmap array. Please help me. Thanks.
case R.id.bupload:
Intent pics=new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pics.setType("image/*");
pics.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(pics,RESULT_LOADS_IMAGE);
break;
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==RESULT_LOADS_IMAGE && resultCode==RESULT_OK && null!=data)
{
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();
Bitmap myselectedImage=BitmapFactory.decodeFile(picturePath);
wphoto.setImageBitmap(myselectedImage);
}
}

Related

Android - Unable to retrieve contact info if third app contacts is being used

my goal is to retrieve a contact's phone number after it gets picked in the contact list. This is the code I am using
private void onClick(){
Intent pickContact = new Intent(Intent.ACTION_PICK);
pickContact.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContact, CONTACT_PICK_CODE);
}
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == CONTACT_PICK_CODE) {
Uri contactData = data.getData();
Cursor cursor = getContentResolver().query(contactData, null, null, null, null);
if (cursor.moveToFirst()) {
int phoneIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String number = cursor.getString(phoneIndex);
}
c.close();
}
}
which works fine if the standard Android contacts app is being used, but crashes when the app "Simple Contacts" is being used.
In particular, the error happens because phoneIndex is -1.
How to make it work even if the user chooses to use another contact list app?
For reference, this is the cursor when the contact gets selected from Simple Contacts.
As you can see it contains only 36 columns, while using the standard contact list app it has 84 columns, one of which is ContactsContract.CommonDataKinds.Phone.NUMBER

Android receiving number, email, etc. from contact

I want to access different contact information like a number, an email etc.
I use code from official Android documentation:
static final int PICK_CONTACT_REQUEST = 1; // The request code
private void pickContact() {
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request it is that we're responding to
if (requestCode == PICK_CONTACT_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// Get the URI that points to the selected contact
Uri contactUri = data.getData();
String[] projection = {Phone.NUMBER};
Cursor cursor = getContentResolver()
.query(contactUri, projection, null, null, null);
cursor.moveToFirst();
// Retrieve the phone number from the NUMBER column
int column = cursor.getColumnIndex(Phone.NUMBER);
String number = cursor.getString(column);
// Do something with the phone number...
}
}
}
The problem is, I can only access phone number and name, other data not. I can change pickContactIntent.setType to Email content type, but that I can access only Email... How can I access different kind of data in this case ?

get path of selected images from gallery using MultipleImageSelect library in android

In my project i need a way of get the path of several images selecteds from the gallery.
I´m using this library MultipleSelectImages
It´s apparently work fine, but in the onActivityResult i need the array with the path of each image, however the result I get is this:
Paths: [com.darsh.multipleimageselect.models.Image#1e6d3057, com.darsh.multipleimageselect.models.Image#33824744]
...when i need the real path (/storage/emulated/0/DCIM/Camera/20150426_110936.jpg)
Reading the doc of the library don´t found solution.
This is the onActivityResult method:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.REQUEST_CODE && resultCode == RESULT_OK && data != null) {
//The array list has the image paths of the selected images
ArrayList<Image> images = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);
Log.i("myLogs", "Paths:" + " " + images);
}
}
...Where "image" it´s imported from the library
import com.darsh.multipleimageselect.models.Image;
I´m not using EXTRA_ALLOW_MULTIPLE because need that the app works in android api 16 version
Thanks in advanced.
Try to use below code;
onActivityResult();-
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 imgPath = cursor.getString(columnIndex);
cursor.close();

how to send/save multiple image from one activity to other?

Suppose i have four or five images whether its from camera or gallery that part i did .Now
i want to have those four or five images to be in another activity how can i do that,
just as u see in olx application.
Can anybody help me in this getting me out of this problem.
below this my code :-
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();
SharedPreferences sp = getSharedPreferences("ImageSharedPref", 0); // Open SharedPreferences with name AppSharedPref
Editor editor = sp.edit();
editor.putString("picturePath", picturePath); // Store selectedImagePath with key "ImagePath". This key will be then used to retrieve data.
editor.commit();
Store all images path in a ArrayList> ,pass this list into intent and in your next activity get all image path by using list index.
Save the paths of those image file in the ArrayList.
Activity A:
ArrayList<Uri> myList = new ArrayList<Uri>();
intent.putExtra("pathList", myList);
Activity B:
ArrayList<Uri> myList = (ArrayList<Uri>) getIntent().getSerializableExtra("mylist");
Once you get the list of paths in Activity B you can always access it using the Uri.
To get the Uri of the image selected from the gallery or the camera:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();

Android Contacts RAW_CONTACT_ID vs CONTACT_ID

I am using a contact picker as follows:
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT)
What I want to know is whether the last path segment of the returned URI is the CONTACT_ID or the RAW_CONTACT_ID.
In case it is the CONTACT_ID, how do I retrieve all RAW_CONTACT_IDs from this contact?
You will get CONTACT_ID as the return data.
In case if you need to get the list of all the RAW_CONTACT_ID of the contact here is what you can include in
#Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == 1) && (resultCode == RESULT_OK)){
Uri contactData = data.getData();
// This gives the value of Contact URI
Cursor c = managedQuery(RawContacts.CONTENT_URI, new String[] {RawContacts._ID}, RawContacts.CONTACT_ID + " = " + contactData.getLastPathSegment(), null, null);
// This query would give you list of Raw_COntact_ID for the added contact
}
}
Do you need to use the CONTACT_ID ?
Otherwise, I recommend you use LOOKUP_KEY instead.
See 1 and 2

Categories

Resources