ANDROID:图片快捷方式导致图库重建相册

发布于 2024-10-20 13:50:46 字数 3460 浏览 5 评论 0原文

我正在通过创建一个应用程序来练习我的 Android 技能,该应用程序只需创建 SD 卡上文件的主屏幕快捷方式,允许 Android 使用默认应用程序打开它们。

一切都很好并且工作正常,但是当我创建图像的快捷方式时,会发生以下情况

  1. 图库显示“加载新相册和照片”Toast几秒钟
  2. Toast消失第二个
  3. Toast重新出现几秒钟
  4. 照片最终显示。

我还应该注意到,当通过另一个文件管理器打开文件时,图库不会显示任何这些 toast,但它确实会在显示高分辨率图像之前显示半秒钟的低分辨率缓冲图像。另请注意,这种行为在多个文件\类型中很明显(无论如何都尝试过 jpeg 和 png)。

这是我对快捷方式本身的意图(路径显然是路径+文件名的字符串):

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

打开快捷方式时,LogCat 告诉我:

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): Building 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

这与 jpeg 的快捷方式相同,除了没有该

ERROR/(1440): Not JPEG: /sdcard/download/TIMETABLE.png

行。奇怪的是,这个错误仍然出现,但画廊可以并且会打开 png。

其他一切似乎都很好(即pdf、音频、视频、文档等)。

无论如何,任何帮助都会非常有帮助,

干杯, 山姆

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

  1. Gallery shows a "Loading new albums and photos" toast for a few seconds
  2. Toast disappears for a second
  3. Toast reappears for a few seconds
  4. 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): Building 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方。的韩爷 2024-10-27 13:50:47

问题解决了!

以后参考,需要指出
mnt/sd卡/...
不是
/sdcard/...

奇怪的是它仍然有效,但画廊变得混乱。

Problem solved!

Future reference, need to point to
mnt/sdcard/...
not
/sdcard/...

It's strange that it still works, but gallery gets confused.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文