System already has something, if we do not have new requirements, direct call is the most direct. Here's how to call a system camera to take pictures and save pictures and how to call a system photo album.
First look at the core method of calling the system camera:
Intent camera = new Intent (mediastore.action_image_capture);
Startactivityforresult (camera, 100);
The data returned by the camera is obtained by the following callback method and processed
@Override
protected void onactivityresult (int requestcode, int resultcode, Intent data) {
Super.onactivityresult (Requestcode, ResultCode, data);
if (Requestcode = = CAMERA && ResultCode = ACTIVITY.RESULT_OK && null!= data) {
Bundle Bundle = data.ge Textras ();
Gets the data returned by the camera and converts it to a picture format
Bitmap Bitmap = (Bitmap) bundle.get ("Data");
}
Here's how to call a system photo album and get a Photo:
Intent picture = new Intent (Intent.action_pick,android.provider.mediastore.images.media.external_content_uri);
Startactivityforresult (picture, 101);
Or
Intent = new Intent (), Intent.settype ("image/*"), Intent.setaction (intent.action_get_content);((activity). Startactivityforresult (Intent, 101);
The following callback methods are appropriate:
@Override
protected void onactivityresult (int requestcode, int resultcode, Intent data) {
Super.onactivityresult (Requestcode, ResultCode, data);
if (Requestcode = && ResultCode = = ACTIVITY.RESULT_OK && null!= data) {
Uri selectedimage = data . GetData ();
String[] Filepathcolumns={mediastore.images.media.data};
Cursor C = this.getcontentresolver (). Query (SelectedImage, Filepathcolumns, null,null,
null);
C.movetofirst ();
int columnindex = C.getcolumnindex (Filepathcolumns[0]);
String picturepath= c.getstring (columnindex);
C.close ();
}
}
Or
@Override
protected void onactivityresult (int requestcode, int resultcode, Intent data) {
if (ResultCode = = Activ ity. RESULT_OK) {
switch (requestcode) {case
:
uri uri = Data.getdata ();
Cursor Cursor = This.getcontentresolver (). Query (URI, NULL,
null, NULL, NULL);
Cursor.movetofirst ();
String Imgno = cursor.getstring (0); Picture number
String imgpath = cursor.getstring (1);//Picture file path
string imgsize = cursor.getstring (2) ; Picture size
String imgname = cursor.getstring (3);//Picture filename
cursor.close ();
Bitmap Bitmap = Bitmapfactory.decodefile (Imgpath);
break;
Default: Return;}}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/