1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
public
void
ChooseImage(View v) {
Intent intent =
new
Intent(Intent.ACTION_GET_CONTENT);
// ACTION_OPEN_DOCUMENT
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(
"image/*"
);
if
(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
startActivityForResult(intent, SELECT_PIC_KITKAT);
}
else
{
startActivityForResult(intent, SELECT_PIC);
}
}
@Override
public
void
onActivityResult(
int
requestCode,
int
resultCode, Intent data) {
if
(RESULT_OK == resultCode) {
switch
(requestCode) {
case
SELECT_PIC_KITKAT:
Uri selectedImage = data.getData();
startPhotoZoom(selectedImage);
break
;
case
3
:
if
(data !=
){
setPicToView(data);
}
break
;
default
:
break
;
}
}
}
public
void
startPhotoZoom(Uri uri) {
Intent intent =
new
Intent(
"com.android.camera.action.CROP"
);
intent.setDataAndType(uri,
"image/*"
);
intent.putExtra(
"crop"
,
"true"
);
intent.putExtra(
"aspectX"
,
1
);
intent.putExtra(
"aspectY"
,
1
);
intent.putExtra(
"outputX"
,
150
);
intent.putExtra(
"outputY"
,
150
);
intent.putExtra(
"return-data"
,
true
);
startActivityForResult(intent,
3
);
}
|