我試圖通過ACTION_SEND意圖從Android圖庫接收圖像。我已經設置了適當的意圖過濾器,畫廊打開我的應用程序。現在我想知道如何獲取圖像數據。我無法在互聯網上找到任何這樣做的例子。我認爲路徑在intent.getData()中的某處,但是我怎樣才能從畫廊中拉出該圖像?從圖庫中接收ACTION_SEND意圖
8
A
回答
15
在Picasa源代碼中找到它。它給出了圖像的正確路徑。
Intent intent = getIntent();
if (Intent.ACTION_SEND.equals(intent.getAction())) {
Bundle extras = intent.getExtras();
if (extras.containsKey(Intent.EXTRA_STREAM)) {
Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
String scheme = uri.getScheme();
if (scheme.equals("content")) {
String mimeType = intent.getType();
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(uri, null, null, null, null);
cursor.moveToFirst();
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(Images.Media.DATA));
0
不能確定SEND意圖,但處理來自PICK意圖的MediaStore相片返回時,它會是這樣的:
Uri selectedImage = intent.getData();
AssetFileDescriptor fd = getContentResolver()
.openAssetFileDescriptor(selectedImage, "r");
FileInputStream s = fd.createInputStream();
// your image data processing code here
不過要小心 - 你可以用5+萬像素的文件中工作,它可能相當大(特別是如果你將它們解壓縮爲位圖來處理),並且你的內存非常有限。
相關問題
- 1. 爲ACTION_SEND意圖
- 2. ACTION_SEND數據意圖
- 3. 從谷歌地圖接收意圖
- 4. 從非活動類接收意圖
- 5. 從類與Android設備意圖接收
- 6. Action_Send意圖不適用於活動
- 7. 意圖ACTION_SEND沒有默認啓動
- 8. Android ACTION_SEND意圖不填充To字段
- 9. 如何從ACTION_SEND中排除特定應用程序意圖?
- 10. 多意圖接收器?
- 11. 如何接收TIME_TICK意圖
- 12. BroadcastReceiver無法接收意圖
- 13. 無法接收ACTION_TIME_CHANGED意圖
- 14. 如何旋轉從相機意圖接收的位圖圖像
- 15. 如何接收意圖。 ACTION_PACKAGE_ADDED意圖。 ACTION_PACKAGE_REMOVED在appwidget中?
- 16. 從服務到意圖的位圖導致RuntimeException接收到廣播意圖
- 17. 在非活動類中接收意圖
- 18. Android從圖庫中按順序接收圖像
- 19. 在廣播接收器中接收呼叫意圖
- 20. 無法分享使用ACTION_SEND意圖圖像微信和Line
- 21. ACTION_SEND意圖是否有額外的指定收件人的名字?
- 22. 廣播接收器ACTION_SEND未顯示
- 23. 在ACTION_SEND上設置接收者emain
- 24. 從等待中的意圖接收廣播的Android問題
- 25. 標題意圖在Android應用程序中的Action_SEND
- 26. MainActivty中的意圖回收
- 27. 接收android內部意圖廣播
- 28. 接收意圖通過代碼
- 29. 如何接收意圖參數
- 30. 確定有效的意圖接收器
在哪個文件中以及該文件的位置是要放置的。 – 2015-04-08 10:17:43