How to select multiple file in android - java

I use following code to select file but i can select one file only. How can i select more then one file.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
.....
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// User has picked an image.
Uri uri = data.getData();
//File URI..
}
thank u

You can create a custom gallery of your own.More info can be had from here.
Android custom image gallery

Related

How I can get image Uri from gallery for a long time?

I'm a junior in android development and I faced a problem with getting Uri for a long time. My aim is get an Image Uri and show the image after few days. I use this method and it works when I restart my app, but in doesn't work when I try to upload image using the same Uri after a day. What i should do to get long Uri?
Intent galleryIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, 1);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1 && resultCode == RESULT_OK){
Uri uri = data.getData();
save(uri.toString());
}
}
because of this URL refers to a local image and I think will not work if you removed this image or renamed it,
you can transform it to base64 and save it in shared preferences or local DB.

Open file from documents on Android Nougat

I'm using file helper class from this post https://stackoverflow.com/a/20559175/2281821 but it doesn't working properly in each case. I'm using Intent chooseIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); to start file picker. I have Android Nougat and I'm receiving from onActivityResult uri: content://com.android.externalstorage.documents/document/home%3Aimage.png
What does this home: means? How can I get access to this file? I was trying with Environment.getExternalStorageDirectory() and System.getenv("EXTERNAL_STORAGE") but I can't get acess.
Following code can be used to get document path:
Intent galleryIntent = new Intent();
galleryIntent .setType("image/*");
galleryIntent .setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryIntent , getString(R.string.app_name)),REQUEST_CODE);
OnActivityResult():
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CODE) {
Uri uri = data.getData();
}
}
}
You can use "uri" variable value to get bitmap. If you want to open document other image also then remove following line:
galleryIntent .setType("image/*");
You get access to a content scheme by opening for instance an InputStream on the uri.
InputStream is = getContentResolver().openInputStream(uri);
BitmapFactory.decodeFromStream(is) will happily read from your stream.

How to get photo from stock galleries other than google Photos in Android Lollipop and higher?

I am using following code to pick an image from gallery.
//Override For uploading the image.
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
}
//for showing the selected image.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==RESULT_LOAD_IMAGE && resultCode==RESULT_OK && data!=null)
{
Uri selectedimage=data.getData();
imagetoupload.setImageURI(selectedimage);
}
}
It only picks an image from google Photos application. I want to pick images from "Gallery" application which comes as stock gallery in phones. While I choose from my Gallery application image is not picked and while showing the seleected image no image is shown.
Use ACTION_GET_CONTENT or ACTION_OPEN_DOCUMENT, depending on the version of Android you are running on, as is covered in the documentation.

Where do i find an image's file path in MediaStore

I'm making an app that picks a image from the gallery and returns the result. I need to get the file path from that selection and store it for later use. I have looked at similar questions and apparently the file path of the image is stored in the column
MediaStore.Images.Media.DATA
How would anyone know that this is the file path? I've looked at the android documentation on MediaStore and it does not tell you where the file path column is. Any help would be appreciated.
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECT_PHOTO);
use this to get an image from gallery, it will return URI of the image which could be store store for later use
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_CANCELED) {
if (requestCode == SELECT_PHOTO) {
Uri path = data.getData();
}
}
}

file chooser for android

I am making an android album app where I can create an album and add photos and delete photos from the album. Adding a photo is a bit tricky where I need a photo filename with a file path. This was very easy using JFileChooser in java but this is android and I have no clue on getting the filename and file path. Is there any thing in the android api where I can get the same functionality as the JFileChooser.
I am looking for a solution to this problem either using a file chooser of some sort or an entire to new approach. Any help is appreciated..
Or is there any other approach I can implement to add a photo...
You may use Intent.ACTION_PICK to invoke an image picker. This intent may be caught by the default gallery app, or some other app installed on the device.
private static final int REQUEST_PICKER = 1;
private void invokePicker() {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Complete action using"), REQUEST_PICKER);
}
Then receive the result on onActivityResult.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK)
return;
if (requestCode == PICK_FROM_FILE) {
// Get Uri of the file selected,
Uri theImageUri = data.getData();
// Or if you want a Bitmap,
Bitmap theBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), theImageUri);
}
}
Edited:
Though in this way you don't need a real file path, you can get it from MediaStore if you need.

Categories