0
我必須實現一個應用程序,只要用戶從手機庫部分打開他/她的任何圖像,就可以將圖像上傳到服務器上。我的問題是如何獲取圖像路徑? 在此先感謝如何在用戶從電話庫中打開圖像路徑時立即獲取圖像路徑?
我必須實現一個應用程序,只要用戶從手機庫部分打開他/她的任何圖像,就可以將圖像上傳到服務器上。我的問題是如何獲取圖像路徑? 在此先感謝如何在用戶從電話庫中打開圖像路徑時立即獲取圖像路徑?
首先調用此意圖來接從圖片庫圖片:
private static final int SELECT_PHOTO = 100;
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
當你從圖庫中選擇圖片做它會自動調用這個onActivityResult
方法:
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case SELECT_PHOTO:
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
try {
yourImageView.setImageBitmap(decodeUri(selectedImage));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
你會在selectedImage
變量中得到圖像路徑。
謝謝。
感謝這和iam意識到它......但我的情況是不同的。我想爲我做一個後臺應用程序或某種廣播接收器觸發從Android手機本地畫廊選擇。 – Ishant
我還沒有任何解決方案呢..沒有想法 – Ishant
是的,你沒有解決方案。但你有沒有嘗試過使用某些東西?谷歌搜索它?或者你想讓我們給你完整的代碼? –
是的,我希望你給我完整的評論代碼...如果你不能慌張親愛的...你的時間了:) – Ishant