009android初级篇之APP中使用系统相机相册等集成应用

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

直接调用系统内部的相机程序,显示的也是系统预设的界面(简单,只有简单的拍照功能);

自己去implement一个相机程序(不难,较具备弹性,但相对复杂);

权限

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

调用系统相机应用

这是第一种方式

在启动相机前先指定好图片的文件位置,通知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报告。

16. android.intent.action.MAIN

决定应用程序最先启动的Activity

17.android.intent.category.LAUNCHER

决定应用程序是否显示在程序列表里

如果只有一个activity的应用程序只声明了 android.intent.action.MAIN ,没有声明 android.intent.category.LAUNCHER,eclipse运行是将报错,桌面也不会有图标。

如果存在多个activity都声明了android.intent.action.MAIN与android.intent.category.LAUNCHER。将会有多个图标在桌面上。

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

参考链接

android在主程序中调用图片,009android初级篇之APP中使用系统相机相册等集成应用...相关推荐

  1. 在Android中调用图片、视频、音频、录音、拍照

    在Android中调用图片.视频.音频.录音.拍照 //选择图片 requestCode 返回的标识 Intent innerIntent = new Intent(Intent.ACTION_GET ...

  2. Android开发 调用系统相机相册图片功能,解决小米手机拍照或者图片横竖相反问题,及小米手机相册图片路径问题

    Android开发 调用系统相机相册图片功能,解决小米手机拍照或者图片横竖相反问题,及小米手机相册图片路径问题 1.调用相机,兼容7.0 AndroidManifest配置 <providera ...

  3. magento中调用图片的方法

    在magento中我们有的时候需要调用图片.我们可以通过几种方式来调用它们,他可以分成几种情况: 1.是在phtml页面中,也就是模板文件中, 在phtml中调用 可以使用<?php echo ...

  4. 常见的图片比例有哪些?App中不同图片比例适用场景

    在现代化的今天,图片在app中随处可见.我们通常只关心图片的内容而没有想过图片的比例其实也有一定讲究.目前常见的图片比例有1:1.2:3.4:3.16:9,为什么不同app中需要用到这些不同的图片比例 ...

  5. android 读取mysql中的图片_Android 通过API获取数据库中的图片文件方式

    Overview 今天复习了一下Android 如何将我们数据库中图片获取出来,并且将其转换为bitmap进行显示. 开发环境以及技术 使用Visual Studio 2019 Android Stu ...

  6. osg中运用Shader(osg初级篇2)

    关于shader的概念,可以参见我的另一篇博客<opengl版本发展史及各种概念的厘清>,这里列举一个例子,用来实现一个特效,屏幕的左半部显示为红色.首先我们准备好两个shader程序: ...

  7. php 将内容中的图片的域名,php给编辑器中的图片地址添加域名

    传统的PC管理后台一般保存的都是图片路径,随着移动端APP的流行,很多平台需要增加API接口.这时发现图片路径并不能被远程读取,下面提供图片路径转换为URL地址的方法:/** * 替换fckedit中 ...

  8. dw读取access中的图片_怎样从Access数据库中读取图片?解决办法

    当前位置:我的异常网» C# » 怎样从Access数据库中读取图片?解决办法 怎样从Access数据库中读取图片?解决办法 www.myexceptions.net  网友分享于:2013-03-0 ...

  9. vue样式中背景图片路径_vue打包css文件中背景图片的路径问题

    vue-cli写完的静态页面我们在node环境中引入没有问题,但是打包后放在Apache环境下,路径却有问题了 如一个简单css语句 .all_bg { background: url(../imag ...

最新文章

  1. 高精度模板 洛谷Luogu P1932 A+B A-B A*B A/B Problem
  2. java自动生成代码框架_DodoFramework- 一个基于代码生成引擎的Java Web系统自动化开发框架...
  3. EntLib.com Forum – 开源ASP.NET论坛 v4.0(提供源码下载)
  4. 转载:关于爱情、伴侣、承诺、人生、
  5. java boolean转int,java如何将int转换为boolean
  6. MYSQL的COMMIT和ROLLBACK
  7. Data Collection with Apache Flume(一)
  8. 2020 Intel数据平面创新赋能未来网络-李雪峰
  9. 标签页添加点击事件和拖拽事件
  10. java类加载机制ClassLoad
  11. showModalDialog和showModelessDialog使用心得*转*
  12. 安卓蓝牙键盘切换输入法_Windows10添加中文美式键盘,传统语言栏,采用ctrl+shift切换输入法...
  13. 文件的读取与写入--ASP.NET中常用代码之四(转载)
  14. GBASE监控工具简介
  15. 计算机excel中百分比怎么算,excel如何自动算百分比
  16. 第1节 虚拟机及常用系统配置步骤
  17. 模拟城市我是市长服务器维护多久,《模拟城市我是市长》你所走过的弯路 新手常见问题...
  18. 18-19款迈巴赫S400改装原厂3D大柏林之声,天籁之音
  19. 我的项目: UConn summer academy BI制药 缺失值处理
  20. Navicat运行sql文件处理失败[ERR] 2006 - MySQL server has gone away解决

热门文章

  1. UML九种图 之 包图和对象图
  2. Nokia 920全部CODE
  3. Bootstrap FileInput(文件上传)中文API整理
  4. Mysql:替换某个字段中的部分字符串——replace函数
  5. 支付宝当面付接口如何计算优惠
  6. SQLServer windows身份验证连接字符串
  7. java基础面试题整理(BAT)
  8. linux搭建乐网服务器,教你linux搭建web服务器
  9. 【剑指offer - C++/Java】9、变态跳台阶
  10. python shelve模块