Reputation: 1
I want to create a button and when i clicked the button it will move me to a grid view where gallery images and videos should show up and we can select multiple videos and images from there and get url of iamges and videos. just like whatsapp and instagram method,
Android development kotlin
firstly i tried to open gallery app and from there wanted to select mutliple images and videos but samsung phone gallery widget doesnt all for multiple selection so thats why i wanted to create a grid view where gallery images and videos should be present and i can select multiple images and videos from there.
Upvotes: 0
Views: 225
Reputation: 123
You can use the new permission less photo picker by android developer team. Its easy to use and you can get Uris of images, videos or both.
https://developer.android.com/training/data-storage/shared/photopicker
Also here is an article with detailed explanation, I think its outdated now as default lib provide all functionality and also provide backward support, but you can get some idea from it.
https://medium.com/tech-takeaways/android-13-photo-picker-with-the-activity-result-api-b4a74572e354
Upvotes: 1
Reputation: 1
Try this code to get images and videos from device U can change MediaStore.Video or Image or File
private ArrayList<imageFolder> getVideoPaths(Context context) {
ArrayList<imageFolder> VideoFolder = new ArrayList<>();
ArrayList<String> picPaths = new ArrayList<>();
Uri allImagesuri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Video.VideoColumns.DATA, MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.BUCKET_DISPLAY_NAME, MediaStore.Video.Media.BUCKET_ID};
Cursor cursor = context.getContentResolver().query(allImagesuri, projection, null, null, null);
try {
if (cursor != null) {
cursor.moveToFirst();
}
do {
imageFolder folds = new imageFolder();
String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME));
String folder = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.BUCKET_DISPLAY_NAME));
String datapath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
//String folderpaths = datapath.replace(name,"");
String folderpaths = datapath.substring(0, datapath.lastIndexOf(folder + "/"));
folderpaths = folderpaths + folder + "/";
if (!picPaths.contains(folderpaths)) {
picPaths.add(folderpaths);
folds.setPath(folderpaths);
folds.setFolderName(folder);
folds.setFirstPic(datapath);
folds.addpics();
VideoFolder.add(folds);
} else {
for (int i = 0; i < VideoFolder.size(); i++) {
if (VideoFolder.get(i).getPath().equals(folderpaths)) {
VideoFolder.get(i).setFirstPic(datapath);
VideoFolder.get(i).addpics();
}
}
}
} while (cursor.moveToNext());
cursor.close();
} catch (Exception e) {
e.printStackTrace();
}
for (int i = 0; i < VideoFolder.size(); i++) {
Log.d("picture folders", VideoFolder.get(i).getFolderName() + " and path = " + VideoFolder.get(i).getPath() + " " + VideoFolder.get(i).getNumberOfPics());
}
//reverse order ArrayList
/* ArrayList<imageFolder> reverseFolders = new ArrayList<>();
for(int i = picFolders.size()-1;i > reverseFolders.size()-1;i--){
reverseFolders.add(picFolders.get(i));
}*/
return VideoFolder;
}
Upvotes: 0
Reputation: 600
In compose you can do that very simple way check below code.
implementation 'androidx.activity:activity-compose:1.6.1'
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeDemoTheme {
var selectedImageUris by remember {
mutableStateOf<List<Uri>>(emptyList())
}
val multiplePhotoPickerLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickMultipleVisualMedia(),
onResult = { uris -> selectedImageUris = uris }
)
LazyColumn(
modifier = Modifier
.fillMaxSize()
) {
item {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceAround
) {
Button(onClick = {
multiplePhotoPickerLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageAndVideo)
)
}) {
Text(text = "Pick media")
}
}
}
items(selectedImageUris) { uri ->
}
}
}
}
}
Upvotes: 0
Reputation: 579
You can use and 3rd party tool for the same. Use this link to get one
This will help you to select multiple images at once and you can get uri for each image and get it uploaded to some server to get their link
Upvotes: 0