Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use adb shell to display a local image

Tags:

android

adb

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?

like image 795
Dan J Avatar asked Jan 03 '13 19:01

Dan J


People also ask

How do I access files using adb?

Open cmd type adb shell then press enter. Type ls to view files list.

How do I use adb platform tools?

Boot your phone into Android, then connect it to your desktop computer with a USB cable. On your computer, launch the Command Prompt and change the directory to point to the platform-tools folder. Type adb devices and hit Enter.

How do I use adb shell in Windows 10?

How to setup ADB on Microsoft Windows. Download the Android SDK Platform Tools ZIP file for Windows. Then open up a Command Prompt from the same directory as this ADB binary. This can be done by holding Shift and Right-clicking within the folder then click the “Open command window here” option.


2 Answers

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.

like image 91
Diego Torres Milano Avatar answered Sep 16 '22 12:09

Diego Torres Milano


The quickest workaround I have for my requirement is to just pull the file off the device and test it on my local machine:

adb pull /storage/sdcard0/Android/data/<mypackage>/files/myfile.jpg ~/Downloads
like image 25
Dan J Avatar answered Sep 18 '22 12:09

Dan J