IF (and this is often a big if) you can guarantee that your screen capture
was the last item added to the MediaStore, you can run a query for it... I
have some sample code here that does this, but it is in C# (Mono for
Android) so you are going to have to port it to Java but it should be
pretty simple:
private string GetLastImagePath()
{
Android.Net.Uri resultUri = GetLastImageUri();
ContentResolver resolver = Context.ContentResolver;
string[] fields = {
MediaStore.Images.ImageColumns.Id,
MediaStore.Images.ImageColumns.Data
};
ICursor imgCursor = MediaStore.Images.Media.Query(resolver,
resultUri, fields, null, null);
if (imgCursor == null || imgCursor.Count <= 0)
return;
imgCursor.MoveToFirst();
string filename =
imgCursor.GetString(imgCursor.GetColumnIndex(MediaStore.Images.ImageColumns.Data));
//Some applications return the file name with a protocol
prepended, so we need to check for that and strip it
Android.Net.Uri fileUri = Android.Net.Uri.Parse(filename);
if (fileUri.Scheme != null)
{
filename = fileUri.SchemeSpecificPart; //Remove the
scheme, e.g. http:
filename = filename.Remove(0, 2); //Remove the two
forward slashes after the scheme
}
return filename;
}
private Android.Net.Uri GetLastImageUri()
{
Android.Net.Uri resultUri = null;
Android.Net.Uri locUri =
MediaStore.Images.Media.ExternalContentUri;
string[] fields = { MediaStore.Images.ImageColumns.Id };
string sort = MediaStore.Images.ImageColumns.DateTaken + "
DESC";
ICursor imgCursor = Context.ContentResolver.Query(locUri,
fields, null, null, sort);
if (imgCursor != null)
{
if (imgCursor.Count > 0)
{
imgCursor.MoveToFirst();
long id = imgCursor.GetLong(imgCursor.GetColumnIndex(
MediaStore.Images.ImageColumns.Id));
resultUri = ContentUris.WithAppendedId(locUri, id);
}
imgCursor.Close();
}
return resultUri;
}
Hope that helps some, though I'm not sure it answers your question
completely... I saw your stackoverflow post about this and there isn't
really a clear cut way to get the info you are looking for.
Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware
On Mon, Mar 12, 2012 at 6:42 AM, scame <[email protected]> wrote:
> Hello.
>
> Is there a way to find out the path used by android to save
> screenshots? Can i get the path from a code?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en