View both Images and Videos in Device Gallery - android

I have the following requirement:
From the mobile application , I want to open the default gallery of the Android tablet / device , which will contain both the image and video files and select them.
Is there any option to view both image and video files on Android Gallery?
Kindly provide your suggestions.

I think, There is no such an option to open both images videos at a time..... But we can filter it before open like this
final CharSequence[] options = {"Images", "Videos", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(OpenGallery.this);
builder.setTitle("Select From...");
builder.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Images")) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(intent, 1);
} else if (options[item].equals("Videos")) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(intent, 1);
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
dialog.dismiss();
}
});
builder.show();

just try this..
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"content://media/internal/images/media"));
startActivity(intent);
Hope it helps ..!

try this
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("images/*,video/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);

Related

android studio through spring mvc

For android studio, I am doing a module where I have to take an image as well as all type files and store into our server. (i.e my sql I am using common backend.) Through Spring MVC, I am doing this project. I am not able to save the file location to mysql.
We have to save only the uploaded location, but that location is our server.
I tried to take the image from mobile, but after taking the image it is not saving. I also granted permission to externalsd.
my code is:
//image selection
private void selectImage() {
Dialog dialog = new Dialog(getActivity());
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Choose Image Source");
builder.setItems(new CharSequence[] { "Gallery", "Camera" },
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
switch (which) {
case 0:
Intent intent = new Intent(
Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
Intent chooser = Intent
.createChooser(
intent,
"Choose a Picture");
startActivityForResult(
chooser,
ACTION_REQUEST_GALLERY);
break;
case 1:
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(
cameraIntent,
ACTION_REQUEST_CAMERA);
break;
default:
break;
}
}
});
builder.show();
dialog.dismiss();
}

How to check is there camera installed in the device or not?

This is my code. I want to select an image from either camera or gallery.
For this i have to check the camera support feature of a device.
public void selectImage() {
final String[] items = new String[]{"Camera", "Gallery"};
final Integer[] icons = new Integer[]{R.drawable.ic_camera, R.drawable.ic_gallery};
ListAdapter adapter = new ArrayAdapterWithIcon(getActivity(), items, icons);
new AlertDialog.Builder(getActivity()).setTitle("Select Picture")
.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Camera")) {
if (//here i want to check is there mobile exists camera or not) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
}
} else if (items[item].equals("Gallery")) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
}
}
}).show();
}
I have tried a lot but no success.
import android.hardware.Camera;`
Use Camera.getNumberOfCameras();. If it returns value greater than 0, it means your device has a camera.
Use this to show gallery to pick image from:
private void showGallery() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, 1234);
}
Use this to open camera (checks if device has camera or not):
private void showCamera() {
// get the package manager and check if device has camera
PackageManager pm = getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// ensure that there is some activity to handle camera intents
if (takePictureIntent.resolveActivity(pm) != null) {
startActivityForResult(takePictureIntent, 5678);
}
} else {
Snackbar.make(mView, "your device dont have camera", Snackbar.LENGTH_LONG).show();
}
}
NOTE: Make sure you declare permission for Camera in the manifest as:
<manifest ... >
<uses-feature android:name="android.hardware.camera"
android:required="true" />
...
</manifest>
For more details, check this out.

No Activity found to handle Intent act=android.intent.action.PICK

I'm trying to implement a function to pick a photo from android built-in gallery (not from SD card) or taking a photo using camera. But "No Activity found to handle Intent act=android.intent.action.PICK" error was returned. My code is as follows:
private void ShowPickDialog() {
new AlertDialog.Builder(this)
.setTitle("Add Photo")
.setNegativeButton("Select from Photos", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(
MediaStore.Images.Media.INTERNAL_CONTENT_URI,
"image/*");
startActivityForResult(intent, 1);
}
})
.setPositiveButton("Take a Pic", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
Intent intent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri
.fromFile(new File(Environment.DIRECTORY_PICTURES,
"image.jpg")));
startActivityForResult(intent, 2);
}
}).show();
}
Can someone plz tell me what the problem is? Also which directory should be used at this line "intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri
.fromFile(new File(Environment.DIRECTORY_PICTURES,
"image.jpg")));
Thanks in advance!

Sending parameters to find which option of intent chooser is clicked while showing both camera and gallery option

Hi I found the following code snippet from another question of stackoverflow to open Camera and Gallery Intent chooser combined. Here's the code.
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT,null);
galleryIntent.setType("image/*");
galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra("Code", OPEN_CAMERA); <-- Not working
Intent chooser = new Intent(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_INTENT, galleryIntent);
chooser.putExtra(Intent.EXTRA_TITLE, "Snap Option");
chooser.putExtra("Code", OPEN_GALLERY); <-- Not working
Intent[] intentArray = {cameraIntent};
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooser,1);
What I want to do is check which intent chooser was clicked when I will be in the onActivityResult . But as mentioned in the code I tried to putExtra params to differentiate and in the onActivityResult I am doing the following to get the code.
int Code = intent.getExtras().getInt("Code");
But this gives me a NullPointerException . How can I do this please help ?
You have to used something for pick the image from..
Like alert box,dialog,custom dialog and many more.i am just guide you how to used alertdialog.
final CharSequence[] items = { "Take Photo", "Choose from Library","Cancel" };
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Add Photo!");
builder.setItems(items, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Take Photo")) {
//you can take photo from camera
/*Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, REQUEST_CAMERA);*/
} else if (items[item].equals("Choose from Library")) {
//you can pick photo from library/gallery
/* Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select File"),SELECT_FILE);*/
} else if (items[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();

Android File Upload Control

I am newbie for android and trying to include a file uploader in android application. But I can't find in any relevant control for that. I want to place a control like this Image
What should I do for achieving this task?
There is no inbuilt control for uploading a file in Android. In java we are having a file-chooser to browse the file. in android you have to do this to select a file either from camera or gallery.
final String[] items = new String[] { "Take picture",
"Choose from Gallery" };
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.select_dialog_item, items);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Image");
builder.setIcon(R.drawable.copy_selected);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) { // pick from
// camera
if (item == 0) {
imageFilepath = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/tmp_img.jpeg";
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageCaptureUri = Uri.fromFile(new File(Environment
.getExternalStorageDirectory().getAbsolutePath(),
"/tmp_img.jpeg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
mImageCaptureUri);
try {
intent.putExtra("return-data", true);
startActivityForResult(intent, PICK_FROM_CAMERA);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
} else { // pick from file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Complete action using"), PICK_FROM_FILE);
}
}
});
final AlertDialog dialog = builder.create();
Now on onActivityResult you need to handle this according to your need.Thanks

Categories

Resources