8

我想用来adb shell告诉我的设备在其 SD 卡上显示图像。我认为这个命令会起作用:

adb shell am start -a android.intent.action.MAIN -n com.android.browser/.BrowserActivity -d file:///storage/sdcard0/Android/data/<mypackage>/files/myfile.jpg

不幸的是,我收到了这个错误:

开始: Intent { act=android.intent.action.MAIN cmp=com.android.browser/.BrowserActivity }
错误类型 3
错误:活动类 {com.android.browser/com.android.browser.BrowserActivity} 不存在。

我也尝试做一个VIEW动作,并尝试只使用-nor-d参数。

adb shell am start -a android.intent.action.VIEW -d file:///storage/sdcard0/Android/data/<mypackage>/files/myfile.jpg

仅使用-d参数会导致此错误(我尝试在路径上使用和不使用“file://”前缀):

开始:Intent { act=android.intent.action.VIEW dat=/storage/sdcard0/Android/data//files/myfile.jpg }
错误:Activity 未启动,无法解析 Intent { act=android.intent.action。查看 dat=/storage/sdcard0/Android/data//files/myfile.jpg flg=0x10000000 }

该文件的权限是:

-rw-rw-r-- root     sdcard_rw   198106 2013-01-02 21:29 gUD9w5.jpg

我正在使用运行 4.1.1 的有根 Galaxy Nexus 进行测试。

更新:我尝试了 dtmilano 的建议,但裁剪工具给出了“无法加载图像”弹出窗口。logcat 的堆栈跟踪是:

ActivityManager: START {dat=file:///storage/sdcard0/Android/data/<mypackage>/Pictures/myfile.jpg typ=image/* 
    flg=0x13000000 cmp=com.google.android.gallery3d/com.android.gallery3d.app.CropImage u=0} from pid 301
UriImage: fail to open: file:///storage/sdcard0/Android/data/<mypackage>/Pictures/myfile.jpg
UriImage: java.io.FileNotFoundException: /storage/sdcard0/Android/data/<mypackage>/Pictures/myfile.jpg: 
    open failed: ENOENT (No such file or directory)
UriImage:   at libcore.io.IoBridge.open(IoBridge.java:416)
UriImage:   at java.io.FileInputStream.<init>(FileInputStream.java:78)
UriImage:   at java.io.FileInputStream.<init>(FileInputStream.java:105)
UriImage:   at android.content.ContentResolver.openInputStream(ContentResolver.java:445)
UriImage:   at com.android.gallery3d.data.UriImage.openOrDownloadInner(UriImage.java:98)
UriImage:   at com.android.gallery3d.data.UriImage.openFileOrDownloadTempFile(UriImage.java:78)
UriImage:   at com.android.gallery3d.data.UriImage.prepareInputFile(UriImage.java:164)
UriImage:   at com.android.gallery3d.data.UriImage.access$100(UriImage.java:40)
UriImage:   at com.android.gallery3d.data.UriImage$RegionDecoderJob.run(UriImage.java:170)
UriImage:   at com.android.gallery3d.data.UriImage$RegionDecoderJob.run(UriImage.java:168)
UriImage:   at com.android.gallery3d.app.CropImage$LoadDataTask.run(CropImage.java:921)
UriImage:   at com.android.gallery3d.app.CropImage$LoadDataTask.run(CropImage.java:913)
UriImage:   at com.android.gallery3d.util.ThreadPool$Worker.run(ThreadPool.java:124)
UriImage:   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
UriImage:   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
UriImage:   at java.lang.Thread.run(Thread.java:856)
UriImage:   at com.android.gallery3d.util.PriorityThreadFactory$1.run(PriorityThreadFactory.java:43)
UriImage: Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
UriImage:   at libcore.io.Posix.open(Native Method)
UriImage:   at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
UriImage:   at libcore.io.IoBridge.open(IoBridge.java:400)
UriImage:   ... 16 more

我想知道这是否是内部 SD 卡,并且图像可能被视为应用程序数据,因此其他应用程序无法访问它?

4

2 回答 2

11

这应该可以工作,但是它取决于您安装的应用程序:

$ adb shell am start -t image/* -d file:///mnt/sdcard/myfile.jpg

有趣的是,如果您在Complete action using...中选择Gallery则不起作用,但如果您选择Crop picture则有效。也适用于Astro Image Viewer

于 2013-01-03T21:30:17.873 回答
3

我的要求最快的解决方法是从设备中提取文件并在我的本地机器上测试它:

adb pull /storage/sdcard0/Android/data/<mypackage>/files/myfile.jpg ~/Downloads
于 2013-01-03T20:34:15.780 回答