[英]Get full accessable path from Android Gallery
我需要從Android Gallery訪問文件並使用POST將其上傳到URL。
沒有問題。 我只是新手來做這些東西,比如訪問設備數據。 我需要有一個提示來獲取我使用Intent和StartActivityForResult從庫中選擇的圖像的完整路徑。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri uri = data.getData();
Bitmap bt = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
}
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE);
要在SD Card.Uri上獲取圖像
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
onActivityResult方法:
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == RESULT_OK) {
Uri photoUri = intent.getData();
if (photoUri != null) {
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this
.getContentResolver(), photoUri);
//Now you can upload this bitmap to server or do something else.
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.