This article describes the Android programming call to Camera and album functions. Share it for your reference, as follows:
xml:
<LinearLayout xmlns:andro android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android: android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Photograph" /> <Button android: android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Photo Album" /> <ImageView android: android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:src="@drawable/ic_launcher" /> </LinearLayout>
activity:
package ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class CameraShowActivity extends Activity { private ImageView mImageView; private Button mButtonCamera; private Button mButtonPhoto; @Override public void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_camera_show); mImageView = (ImageView) (.imageview_preview); mButtonCamera = (Button) (.button_cameraButton); mButtonPhoto = (Button) (.button_photoButton); (new OnClickListener() { //Open Camera @Override public void onClick(View v) { Intent intent = new Intent(".IMAGE_CAPTURE"); (MediaStore.EXTRA_OUTPUT, (new File(Environment .getExternalStorageDirectory(), ""))); (MediaStore.EXTRA_VIDEO_QUALITY, 0); startActivityForResult(intent, 10); } }); (new OnClickListener() { //Get photo album @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); (Intent.CATEGORY_OPENABLE); ("image/*"); ("crop", "true"); ("aspectX",1); ("aspectY",1); ("outputX", 80); ("outputY", 80); ("return-data",true); startActivityForResult(intent, 11); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 10 && resultCode == Activity.RESULT_OK) { ((new File( (), "") .getAbsolutePath())); ("data-->"+data); }else if (requestCode == 11 && resultCode ==Activity.RESULT_OK) { ("data2-->"+data); } } }
<manifest xmlns:andro package="" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <uses-permission android:name="" /> <uses-permission android:name=".MOUNT_UNMOUNT_FILESYSTEMS" /> <uses-permission android:name=".WRITE_EXTERNAL_STORAGE" /> <uses-feature android:name="" /> <uses-feature android:name="" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".CameraShowActivity" android:label="@string/title_activity_camera_show" > <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> </activity> </application> </manifest>
android calls the picture in the album and returns
Intent intent=new Intent(Intent.ACTION_GET_CONTENT); (Intent.CATEGORY_OPENABLE); ("image/*"); ("crop", "true"); ("aspectX", 1); ("aspectY", 1); ("outputX", 80); ("outputY", 80); ("return-data", true); startActivityForResult(intent, 0);
Get the selected image in the original activity as follows:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { (resultCode); Bitmap cameraBitmap = (Bitmap) ().get("data"); (requestCode, resultCode, data); }
PS: For file-related attribute functions, please refer to the online tools of this site:
Android Manifest function and permission description:
http://tools./table/AndroidManifest
For more information about Android related content, please check out the topic of this site:Summary of Android photography and picture processing skills》、《Summary of Android graphics and image processing skills》、《Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.