22
33import android .app .Activity ;
44import android .app .NotificationManager ;
5- import android .content .ActivityNotFoundException ;
65import android .content .Intent ;
6+ import android .database .Cursor ;
7+ import android .graphics .Bitmap ;
8+ import android .graphics .BitmapFactory ;
9+ import android .net .Uri ;
710import android .os .Bundle ;
11+ import android .provider .MediaStore ;
12+ import android .util .Log ;
13+ import android .widget .ImageView ;
14+
15+ import com .androidhuman .example .CameraPreview2 .R ;
816
917public class GalleryActivity extends Activity {
1018
@@ -14,23 +22,60 @@ public class GalleryActivity extends Activity {
1422 @ Override
1523 protected void onCreate (Bundle savedInstanceState ) {
1624 super .onCreate (savedInstanceState );
25+ setContentView (R .layout .activity_image );
1726
27+ // Intent intent = new Intent();
28+ //
29+ // intent.setType("image/*");
30+ // intent.setAction(Intent.ACTION_GET_CONTENT);
31+ //// Log.i("yoon", "income gallery Class");
32+ // try{
33+ //
34+ // startActivityForResult(intent.createChooser(intent, "Complete"),PICK_FROM_GALLERY);
35+ // } catch (ActivityNotFoundException e){
36+ //
37+ // }
1838 Intent intent = new Intent ();
19-
2039 intent .setType ("image/*" );
2140 intent .setAction (Intent .ACTION_GET_CONTENT );
22-
23- try {
24-
25- startActivityForResult (intent .createChooser (intent , "Complete" ),PICK_FROM_GALLERY );
26- } catch (ActivityNotFoundException e ){
27-
28- }
41+ startActivityForResult (intent , 2 );
2942 // notification 매니저 생성
43+ Log .i ("yoon" ,"start img view" );
3044 NotificationManager nm =
3145 (NotificationManager )getSystemService (NOTIFICATION_SERVICE );
3246
3347 // 등록된 notification 을 제거 한다.
3448 nm .cancel (1234 );
3549 }
50+ @ Override
51+ public void onActivityResult (int requestCode , int resultCode , Intent data ) {
52+ super .onActivityResult (requestCode , resultCode , data );
53+ if (requestCode == PICK_FROM_GALLERY && resultCode == Activity .RESULT_OK ) {
54+ if (data == null ) {
55+ //Display an error
56+ return ;
57+ }
58+
59+ Uri selectedImage = data .getData ();
60+ String [] filePathColumn = { MediaStore .Images .Media .DATA };
61+
62+ Cursor cursor = getContentResolver ().query (selectedImage ,
63+ filePathColumn , null , null , null );
64+ cursor .moveToFirst ();
65+
66+ int columnIndex = cursor .getColumnIndex (filePathColumn [0 ]);
67+ String picturePath = cursor .getString (columnIndex );
68+ cursor .close ();
69+
70+ Bitmap bitmap = BitmapFactory .decodeFile (picturePath );
71+ // image.setImageBitmap(bitmap);
72+
73+ if (bitmap != null ) {
74+ ImageView rotate = (ImageView ) findViewById (R .id .img_result );
75+ rotate .setImageBitmap (bitmap );
76+
77+ }
78+ //Now you can do whatever you want with your inpustream, save it as file, upload to a server, decode a bitmap...
79+ }
80+ }
3681}
0 commit comments