android应用中使用相机功能,大致有两种方式实现:

  1. 直接调用系统内部的相机程序,显示的也是系统预设的界面(简单,只有简单的拍照功能);
  2. 自己去implement一个相机程序(不难,较具备弹性,但相对复杂);

权限

如果需要拍照功能,则需要在AndroidManifest.xml文件中添加权限:

<uses-permission android:name="android.permission.CAMERA"/>

调用系统相机应用

这是第一种方式

在启动相机前先指定好图片的文件位置,通知intent,同时也保留在成员变量中。然后在函数中,可以直接打开该文件

private static  final  int CAMERA_REQUESTCODE=1;

String sFileFullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.jpg";
Log.e("onNavi","file: "+sFileFullPath);
File file = new File(sFileFullPath);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, CAMERA_REQUESTCODE);

获取返回值

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUESTCODE) {
if (resultCode == RESULT_OK) {
////Bitmap bmPhoto = (Bitmap) data.getExtras().get("data");
// You can set bitmap to ImageView here 这里可以获得相片的缩略图
}
}
}

第二种方式:自定制camera

参考链接, 该功能我未实现

Android 自定义camera

同样的方法可以调用系统相册

private static final  int REQUESTCODE_PICK=2;

Intent mIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(mIntent,REQUESTCODE_PICK);

在onActivityResult中获得选择的图片

if(requestCode == REQUESTCODE_PICK) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Log.e(TAG,"Select image "+picturePath);
}

Intent常用的ACTION

1. Intent.Action_CALL

android.intent.action.CALL

呼叫指定的电话号码。

Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:10086");
startActivity(intent);

2.Intent.Action.DIAL

String: action.intent.action.DIAL

调用拨号面板

Intent intent=new Intent();

intent.setAction(Intent.ACTION_DIAL);

intent.setData(Uri.parse("tel:10086");

startActivity(intent);

3.Intent.Action.ALL_APPS

String: andriod.intent.action.ALL_APPS

列出所有的应用。

4. Intent.ACTION_CALL_PRIVILEGED

String:android.intent.action.CALL_PRIVILEGED

调用skype的action

    Intent intent = newIntent("android.intent.action.CALL_PRIVILEGED");
intent.setClassName("com.skype.raider",
"com.skype.raider.Main");
intent.setData(Uri.parse("tel:" + phone));
startActivity(intent);

5. Intent.Action_CALL_BUTTON

String: android.action.intent.CALL_BUTTON.

相当于按“拨号”键。

Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);

startActivity(intent);

6. Telephony.SMS_RECEIVED

String: android.provider.Telephony.SMS_RECEIVED

接收短信的action

7. Intent.ACTION_GET_CONTENT

String: android.intent.action.GET_CONTENT

允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)

8. Intent.ACTION_BATTERY_LOW;

String: android.intent.action.BATTERY_LOW

表示电池电量低

9. Intent.ACTION_SEND

String: android.intent.action.Send

发送邮件的action

10. Intent.ACTION_CLOSE_SYSTEM_DIALOGS

当屏幕超时进行锁屏时,当用户按下电源按钮,长按或短按(不管有没跳出话框),进行锁屏时,android系统都会广播此Action消息

11. Intent.ACTION_MAIN

String: android.intent.action.MAIN

标识Activity为一个程序的开始。

12. Intent.ACTION_POWER_CONNECTED;

插上外部电源时发出的广播

13 Intent.ACTION_POWER_DISCONNECTED;

已断开外部电源连接时发出的广播

14.Intent.ACTION_ANSWER

Stirng:android.intent.action.ANSWER

处理呼入的电话。

15 .Intent.ACTION_BUG_REPORT

String: android.intent.action.BUG_REPORT

显示Dug报告。

action的操作有很多,需要的话,继续百度。

参考链接

Android 如何从系统图库中选择图片

009android初级篇之APP中使用系统相机相册等集成应用的更多相关文章

  1. 008android初级篇之jni中数组的传递

    008android初级篇之jni中数组的传递 jni中在native中数据类型的实际类型 jchar 占两个字节,跟native c中的char(占一个字节)是两个数据类型 jbyte, unsig ...

  2. iOS中 自定义系统相机 作者:韩俊强

    需要框架: #import <AVFoundation/AVFoundation.h> #import <AssetsLibrary/AssetsLibrary.h> 布局如下 ...

  3. 【踩坑速记】MIUI系统BUG,调用系统相机拍照可能会带给你的一系列坑,将拍照适配方案进行到底!

    一.写在前面 前几天也是分享了一些学习必备干货(还没关注的,赶紧入坑:传送门),也好久没有与大家探讨技术方案了,心里也是挺痒痒的,这不,一有点闲暇之时,就迫不及待把最近测出来的坑分享给大家. 提起An ...

  4. [转帖]APP逆向神器之Frida【Android初级篇】

    APP逆向神器之Frida[Android初级篇] https://juejin.im/post/5d25a543e51d455d6d5358ab 说到逆向APP,很多人首先想到的都是反编译,但是单看 ...

  5. Android中获取系统上安装的APP信息

    Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:00000099 EndFragment:00003259 Android中获取系统上安装的APP信 ...

  6. 在Eclipse中使用JUnit4进行单元测试(初级篇、中级篇、高级篇)

    本文转载自以下 初级篇: http://blog.csdn.net/andycpp/article/details/1327147 中级篇: http://blog.csdn.net/andycpp/ ...

  7. 25个增强iOS应用程序性能的提示和技巧(初级篇)

    25个增强iOS应用程序性能的提示和技巧(初级篇) 标签: ios内存管理性能优化 2013-12-13 10:53 916人阅读 评论(0) 收藏 举报  分类: IPhone开发高级系列(34)  ...

  8. 移动端https抓包那些事--初级篇

    对于刚刚进入移动安全领域的安全研究人员或者安全爱好者,在对手机APP进行渗透测试的时候会发现一个很大的问题,就是无法抓取https的流量数据包,导致渗透测试无法继续进行下去. 这次给大家介绍一些手机端 ...

  9. maven的使用--初级篇

    一.前言         早就知道maven 在java 项目的管理方面名声显赫,于是就想着学习掌握之,于是查阅了大量文档.发现这些文档的作者都是java 的大腕,大多都是站在掌握了一定maven 基 ...

随机推荐

  1. 大数据的开始:安装hadoop

    为实现全栈,从今天开始研究Hadoop,个人体会是成为某方面的专家需要从三个方面着手 系统化的知识(需要看书或者比较系统的培训) 碎片化的知识(需要根据关注点具体的深入的了解) 经验的积累(需要遇到问 ...

  2. CentOS release 6.6 (Final)如何安装firefox和chromium

    一.firefox的安装: 1. 安装remi源 rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8 ...

  3. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:3.安装Oracle RAC-3.5.安装oracle11gr2 database 软件与创建数据库

    3.5.安装oracle11gr2 database 软件与创建数据库 3.5.1.安装Oracle 11gr2 Database 以oracle 用户登录到节点一,切换到软件安装目录,执行安装. 在 ...

  4. Flask+uwsgi+Nginx环境搭建

    开源软件准备需要的软件列表:setuptools-33.1.1.zipPython-2.7.13.tgzpip-9.0.1.tar.gznginx-1.10.3.tar.gz软件统一上传到/usr/l ...

  5. javascript快速入门19--定位

    元素尺寸 获取元素尺寸可以使用下面几种方式 元素的style属性width,height,但这些属性往往返回空值,因为它们只能返回使用行内style属性定义在元素上的样式 元素的currentStyl ...

  6. solr 统计频率(term frequency)

    1.统计单词在某个字段出现的频率次数 term frequency实现使用了function query. 例如统计‘公司’这个关键字在text这个字段中出现的次数 在返回的时候进行计算统计,即在返回 ...

  7. Docker核心技术

    Docker核心技术 1.cgroup 即controller group,其重要概念是子系统,首先挂载子系统,然后才有control group.例如cpu子系统,挂载至系统之后,创建一个cgrou ...

  8. 小程序image的13种mode

    注:image组件默认宽度300px.高度225px mode 有效值: mode 有 13 种模式,其中 4 种是缩放模式,9 种是裁剪模式. 缩放: 裁剪:                 文章来 ...

  9. odoo8编辑视图中sheet边距过宽问题调整

    在Odoo8的Form视图中,预设有一个sheet的边距,这样看起来像是在一页纸上录入信息,但因为现在的显示器比较宽,预设的sheet宽度比较小,这样看起来就浪费了大量的空间,尤其是明细字段比较多的时 ...

  10. 【DB2】对两列分组之后判断另外一列是否有重复

    建立表数据如下: ),sex ),sex_nm ),OWER ),TYPE ),TYPE_NM )); ,','水果'), (,','水果'), (,','水果'), (,','水果'), (,',' ...