i need to Know how to insert video to android gallery or make my own folder in gallery to shows my app photos and videos
for example if i have my photo pathe like this
File file = new File(storagePath, FileName);
String MyPath= ""+Uri.fromFile(file);
what is the next step ?
Related
I just started learning about uploading files and images to s3 bucket in android. I have been able to learn how to upload files and it works (I see it in my bucket), however, the problem is that it saves as a file which cannot be opened, instead of an image that it is.
I get the uri from the onActivityResult just like this:
Uri selectedImg=data.getData();
String[]filePathColumn={MediaStore.Images.Media.DATA};
Cursor cursor=getContentResolver().query(selectedImg,filePathColumn,null,null,null);
cursor.moveToFirst();
int columnIndex=cursor.getColumnIndex(filePathColumn[0]);
imgString=cursor.getString(columnIndex);
and create the File using the 'imgString' variable:
File imageFile = new File(imgString);
and then I pass imageFile into the s3 upload method:
TransferObserver observer = transferUtility.upload(
MY_BUCKET, objectkey, imageFile);
and it does upload. But when I go to the bucket, it is not saved as an image (say 'imageFile.jpg'), but just as a file which cannot be read or accessed ('imageFile'). What am I doing wrong? am I supposed to pass in the file extension to let the bucket know its an image? I looked online but that does not seem to matter, plus the uri does contain the .jpg ( or .png) extension, so I'm not sure why it does not seem to work
I need to display an image and some HTML associated with it in a WebView. I get the image as byte[]. I am creating a .PNG file using the following code.
private string CreatePNG(byte[] data)
{
string filePath = Android.OS.Environment.ExternalStorageDirectory.Path;
string fileName = System.Guid.NewGuid().ToString() + ".png";
File.WriteAllBytes(Path.Combine(filePath, fileName), data);
return Path.Combine(filePath, fileName);
}
Then I embed the .PNG file in my HTML using the following code.
html += #"<img src=""file://" + CreatePNG(page.DocumentImage) + "\"/><br><br>";
The image shows as blank in my app. The text shows properly. If I try to open the image directly on the phone after browsing from "File Manager", it still shows as blank. When I copy the image from the phone to my Mac, it opens up fine.
Can someone please advise what is going wrong here?
How to upload the entire folder of images (in the particular directory) onto Dropbox using Dropbox API?
In the sample code, it uploads the particular file which is of the same filename, however, I saved the image filenames according to the time at which it is taken and therefore, I was not able to upload any file saved.
I tried to use:
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
String imageFileName = "Pictures" + date.toString()+ ".jpg";
File file = new File(path+File.separator, imageFileName);
But no file was found when I tried uploading.
I have a problem when saving image from web.
I create new folder and save all images to this. The problem is I want this folder order by the last download image on first but When i open gallery, the folder is order by the image date created and the date created in the downloaded image is not the time I download but the first time it created. I've already search on stack over flow and see that java can't modified the date created in image to the time I download it.
Any one has the solution? (Sorry for the bad English)
Thanks you for the comment. I will explain more details.
First, I download image from web to cache directory
HttpURLConnection localHttpURLConnection = (HttpURLConnection) new java.net.URL(urldisplay).openConnection();
localHttpURLConnection.setConnectTimeout(30000);
localHttpURLConnection.setReadTimeout(30000);
localHttpURLConnection.setInstanceFollowRedirects(true);
InputStream in = localHttpURLConnection.getInputStream();
File localFile = Constans.fileCache.getCacheFile(urldisplay);
FileOutputStream fos = new FileOutputStream(localFile);
Utils.CopyStream(in, fos); // simple copy by trunks
fos.close();
Second, I copy downloaded image to external storage
File toFile = new File(Environment.getExternalStorageDirectory() + "/folder", "folder_" + System.currentTimeMillis() + ".png");
FileOutputStream fos = new FileOutputStream(toFile);
Utils.CopyStream(new FileInputStream(fromFile), fos);
fos.close();
// Scan image to display when open with gallery otherwise it couldn't see in gallery
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(toFie);
mediaScanIntent.setData(contentUri);
mContext.sendBroadcast(mediaScanIntent);
Lastly, I see that gallery don't sort my image by the time I downloaded. That is the problem i want to fix.
Not sure I understood, but let's try.
First the issue you mention is more specific to Gallery application than a java code issue.
I assume Gallery use EXIF information to order the picture by date they were taken, not oder they are downloaded/copied. Unfortunatly Gallery does not provide any option to sort picture in other oders.
Maybe you can try to use another explorer that allows you to sort the pictures in another order (maybe ESFileExplore which has more options?)
Ultimate solution: you can try to change EXIF in your pictures using a java EXIF library to modify picture taken date and this should change the order they appear in the Galery (but very ugly solution...). Some random EXIF libraries after 5 seconds of Google:
http://drewnoakes.com/code/exif/
http://www.toanthang.net/modules.php?name=News&new_topic=2&catid=7
Hope this helps
Thierry
I am working on an application, where i take pictures from a camera and store it in a separate folder in sd card. The problem what i am facing is, once the pictures are stored in a folder on sd card the Image folder is not being displayed in android native gallery.
This should be something similar to whatsapp image folder. how is it possible?
use the function MediaStore.Images.Media.insertImage to create a thumbnail and show the image in the default android gallery.
String imageName = "imagepath";
File sdImageMainDirectory = new File(imageName);
MediaStore.Images.Media.insertImage(getContentResolver(),
sdImageMainDirectory.getAbsolutePath(),sdImageMainDirectory.getName(), "description");
You need to let the system know that new media has been added before it will show up. Call this after you save the image.
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));