ANDROID: Image Shortcut Causes Gallery to Rebuild Albums
I'm practicing my Android skills by creating an app that simply creates home screen shortcuts to files on the sdcard, allowing android to open them with their default application.
All is good and working, however when I create a shortcut to an image the following happens
- Gallery shows a "Loading new albums and photos" toast for a few seconds
- Toast disappears for a second
- Toast reappears for a few seconds
- Photo finally shows.
I should also note that when opening the file through another file manager, gallery does not show any of these toasts, however it does show a low res buffered looking image for half a second before showing the hi-res one. Also note, this behavior is evident with several files\types (tried jpegs and pngs anyway).
This is my intent for the shortcut itself (path is obviously a string of the path + filename):
Intent shortcutIntent = new Intent ();
shortcutIntent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(path);
Uri uri = Uri.fromFile(file);
MimeTypeMap map = MimeTypeMap.getSingleton();
String mime = map.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(uri.toString().toLowerCase()));
shortcutIntent.setDataAndType(uri, mime);
On opening the shortcut LogCat tells me:
03-08 19:34:16.431: INFO/ActivityManager(167): Starting: Intent { act=android.intent.action.VIEW dat=file:///sdcard/download/TIMETABLE.png typ=image/png flg=0x14000000 cmp=com.cooliris.media/.Gallery bnds=[15,159][144,269] } from pid 262
03-08 19:34:16.480: INFO/Gallery(1440): onDestroy
03-08 19:34:16.511: INFO/Gallery(1440): onCreate
03-08 19:34:16.621: DEBUG/CacheService(1440): Refreshing Cache for all items
03-08 19:34:16.621: INFO/CacheService(1440): Refreshing cache.
03-08 19:34:16.721: INFO/CacheService(1440): Building albums.
03-08 19:34:16.791: INFO/RenderView(1440): First Draw
03-08 19:34:16.831: INFO/CacheService(1440): Done building albums.
03-08 19:34:16.831: INFO/CacheService(1440): Building items.
03-08 19:34:16.971: INFO/ActivityManager(167): Displayed com.cooliris.media/.Gallery: +498ms
03-08 19:34:17.001: INFO/CacheService(1440): Done building items.
03-08 19:34:17.011: INFO/MediaFeed(1440): Replacing media set 310386146
03-08 19:34:17.011: INFO/MediaFeed(1440): Replacing media set 1506676782
03-08 19:34:17.011: INFO/MediaFeed(1440): Replacing media set -1928128949
03-08 19:34:17.171: DEBUG/dalvikvm(167): GC_EXPLICIT freed 690K, 41% free 5902K/9991K, external 1612K/2124K, paused 109ms
03-08 19:34:17.361: DEBUG/dalvikvm(1083): GC_EXPLICIT freed 175K, 52% free 2678K/5575K, external 0K/0K, paused 35ms
03-08 19:34:18.521: DEBUG/AlarmManagerService(167): Kernel timezone updated to -660 minutes west of GMT
03-08 19:34:18.531: DEBUG/SystemClock(275): Setting time of day to sec=1299573259
03-08 19:34:26.127: ERROR/(1440): Not JPEG: /sdcard/download/TIMETABLE.png
03-08 19:34:26.138: DEBUG/CacheService(1440): Refreshing Cache for all items
03-08 19:34:26.138: INFO/CacheService(1440): Refreshing cache.
03-08 19:34:26.197: INFO/CacheService(1440): Building albums.
03-08 19:34:26.258: INFO/CacheService(1440): Done building albums.
03-08 19:34:26.258: INFO/CacheService(1440): Bu开发者_运维百科ilding items.
03-08 19:34:26.348: INFO/CacheService(1440): Done building items.
03-08 19:34:26.348: DEBUG/CacheService(1440): No items found for album
03-08 19:34:26.348: INFO/GridLayer(1440): Slot changing from -1 to -1
03-08 19:34:26.358: INFO/RenderView(1440): Texture creation fail, glError 1281
03-08 19:34:26.388: WARN/MediaProvider(1083): original media doesn't exist or it's canceled.
03-08 19:34:26.388: INFO/CacheService(1440): Built thumbnail and screennail for 0 in 33
This is the same for shortcuts to jpegs except without the
ERROR/(1440): Not JPEG: /sdcard/download/TIMETABLE.png
line. It's weird that that error still comes up but gallery can and will open the pngs.
Everything else seems to be fine (ie pdfs, audio, video, documents etc etc etc).
Anyway any assistance would be extremely helpful,
Cheers, Sam
Problem solved!
Future reference, need to point to mnt/sdcard/... not /sdcard/...
It's strange that it still works, but gallery gets confused.
精彩评论