Search code examples
androidadb

How to use adb shell to display a local image


I want to use adb shell to tell my device to display an image on its SD card. I thought this command would work:

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

Unfortunately I get this error:

Starting: Intent { act=android.intent.action.MAIN cmp=com.android.browser/.BrowserActivity }
Error type 3
Error: Activity class {com.android.browser/com.android.browser.BrowserActivity} does not exist.

I also tried doing a VIEW action, and trying with only the -n or the -d parameters.

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

Using only the -d parameter results in this error (I tried both with and without the "file://" prefix on the path):

Starting: Intent { act=android.intent.action.VIEW dat=/storage/sdcard0/Android/data//files/myfile.jpg }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=/storage/sdcard0/Android/data//files/myfile.jpg flg=0x10000000 }

The permissions on the file are:

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

I'm testing with a rooted Galaxy Nexus running 4.1.1.

Update: I tried dtmilano's suggestion but the Crop tool gives a "Couldn't load the image" popup. The stack trace from logcat is:

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

I'm wondering if this is an internal SD card, and maybe the images are being treated as application data, so other apps can't access it?


Solution

  • This should work, however it's dependant on the apps you have installed:

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

    Interestingly, it doesn't work if you select Gallery in Complete action using..., but works if you select Crop picture. Also works with Astro Image Viewer.