android studio through spring mvc - android

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();
}

Related

Insert LongPress from listview

I tried to introduce long press.
this time using a alertdialog to the 2 options there, play and delete.
so I would like to offer longpress for delete and touch for play. How can I do?
code:
#Override
public void onVideoSelected(final String uri, String mimeType) {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
builder.setTitle("Select");
// builder.setMessage("Lorem ipsum dolor ....");
builder.setItems(new CharSequence[]
{getString(R.string.play_video), getString(R.string.remove_video)},
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
Intent intent = new Intent(Main2Activity.this, MainActivity.class);
intent.putExtra("url", uri);
startActivity(intent);
break;
case 1:
File file = new File(uri);
file.delete();
Main2Activity.this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(uri))));
break;
}
}
});
builder.create().show();
}

View both Images and Videos in Device Gallery

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);

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