Back to project page Patio.
The source code is released under:
MIT License
If you think the Android project Patio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.andressantibanez.android.patio; /*from w w w . jav a 2 s .com*/ import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class PatioUtils { public static String getRealPathFromURI(Context context, Uri contentURI) { String result = null; Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if(cursor != null) { cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); result = cursor.getString(idx); cursor.close(); } return result; } public static File getNewImageFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); return File.createTempFile(imageFileName, ".jpg", storageDir); } public static void addNewImageToGallery(Context context, String filePath) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); File f = new File(filePath); Uri contentUri = Uri.fromFile(f); mediaScanIntent.setData(contentUri); context.sendBroadcast(mediaScanIntent); } }