Android使用Intent调用摄像头并获取照片

本文介绍了如何在Android应用中使用Intent启动相机并获取拍摄的照片。通过调用MediaStore.ACTION_IMAGE_CAPTURE启动相机,然后在onActivityResult中处理返回结果。当requestCode匹配且data不为空时,可以从Intent的extras中获取Bitmap图像。
摘要由CSDN通过智能技术生成

使用Android的Intent调用另外一个activity的时候,采用的是异步方式。startActivityForResult之后被调用activity并没有马上返回结果给调用activity,Android的Acitivity对象中startActivityForResult的源代码中有相关的解释。

可以重载activity的onActivityResult() 方法,完成事件的处理。

    

/**

     * Launch an activity for which you would like a result when it finished.

     * When this activity exits, your

     * onActivityResult() method will be called with the given requestCode.

     * Using a negative requestCode is the same as calling

     * { @link  #startActivity} (the activity is not launched as a sub-activity).

     *

     * <p>Note that this method should only be used with Intent protocols

     * that are defined to return a result.  In other protocols (such as

     * { @link  Intent#ACTION_MAIN} or { @link  Intent#ACTION_VIEW}), you may

     * not get the result when you expect.  For example, if the activity you

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值