android 摄像头 简书,Android12-调用摄像头和相册

运行结果如下:

2017-04-13_16-20-51.gif

第一步:搭建界面布局

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/take_photo"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="拍照上传"/>

android:id="@+id/choose_from_album"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="从相册中选择照片"/>

android:id="@+id/picture"

android:layout_width="match_parent"

android:layout_height="match_parent"

/>

第二步:在Activity中实现功能

public class MainActivity extends AppCompatActivity {

public static final int TAKE_PHOTO = 1;

private ImageView picture;

private Uri imageUri;

public static final int CHOOSE_PHOTO = 2;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.layout_main);

Button takePhoto = (Button) findViewById(R.id.take_photo);

picture = (ImageView) findViewById(R.id.

你可能感兴趣的:(android,摄像头,简书)