2013-01-03 50 views
5

我想使用adb shell告訴我的設備在其SD卡上顯示圖像。我想這個命令會工作:如何使用adb外殼來顯示本地圖像

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

不幸的是我得到這個錯誤:

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.

我也試圖做一個VIEW動作,並且只用-n-d參數嘗試。

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

此錯誤只使用-d參數結果(我試過有和沒有的「文件://」的路徑前綴):

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 }

上的文件的權限是:

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

我使用的是運行4.1.1的rooted 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卡,也許圖像被視爲應用程序數據,以便其他應用不能訪問它?

+0

它應該與'VIEW'一起工作並且不需要'-n com.android.browser/.BrowserActivity'。然後系統應該將意圖解決到正確的課程。 – iagreen

+0

這似乎並沒有爲我工作,我已更新與我看到的錯誤的問題。 –

+0

安裝一個文件管理器應用程序,並嘗試瀏覽和查看它 - 應回答權限問題。也許該文件是可訪問的,但不是通過該路徑名稱*到應用程序用戶的*。 –

回答

6

這應該工作,但是它依賴於你所安裝的應用程序:

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

有趣的是,如果你使用...在完成操作選擇畫廊這是行不通的,但如果你選擇工作作物圖片。 也適用於Astro Image Viewer

+0

或使用-t「image/*」,因爲發佈的代碼是jpg。 – iagreen

+0

只要看到「使用...的完整操作」彈出窗口,我總能看到「無法加載圖像」。也許問題是我的路徑格式(我試了很多),或者如果這是一個內部SD卡,那麼也許權限正在阻止其他應用程序訪問該文件。 –

+0

首先將圖像文件添加到SD卡的根目錄並驗證是否有效。然後去其他地方。 –

2

最快的解決方法我有我的要求是隻拉文件關閉設備和測試它在我的本地機器上:

adb pull /storage/sdcard0/Android/data/<mypackage>/files/myfile.jpg ~/Downloads