009android初级篇之APP中使用系统相机相册等集成应用
2015-11-06 17:45
441 查看
android应用中使用相机功能,大致有两种方式实现:
直接调用系统内部的相机程序,显示的也是系统预设的界面(简单,只有简单的拍照功能);
自己去implement一个相机程序(不难,较具备弹性,但相对复杂);
在启动相机前先指定好图片的文件位置,通知intent,同时也保留在成员变量中。然后在函数中,可以直接打开该文件
获取返回值
第二种方式:自定制camera
参考链接, 该功能我未实现
Android 自定义camera
在onActivityResult中获得选择的图片
呼叫指定的电话号码。
调用拨号面板
Intent intent=new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:10086");
startActivity(intent);
列出所有的应用。
调用skype的action
相当于按“拨号”键。
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
startActivity(intent);
接收短信的action
允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)
表示电池电量低
发送邮件的action
标识Activity为一个程序的开始。
处理呼入的电话。
显示Dug报告。
action的操作有很多,需要的话,继续百度。
直接调用系统内部的相机程序,显示的也是系统预设的界面(简单,只有简单的拍照功能);
自己去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 如何从系统图库中选择图片相关文章推荐
- Android 从java字节码告诉你 为什么Handler会造成内存泄露
- Android RSA加密对象数据
- 属性 iOS笔记
- 属性 iOS笔记
- iOS——计算项目代码行数
- iOS开发20-iOS开发中要注意的循环引用
- Android开发的那些坑和小技巧
- Android控件之Spinner
- Android初学习 - 国际化
- android开发--Activity之间的跳转实现、activity传参
- iOS学习之CALayer
- 【ORM】--FluentNHibernate之AutoMapping详解
- 将一个List(Object)中的Object根据相同属性名的值整合到一个两层List(List(Object))
- IOC容器——Unity
- 【Android】如何调节屏幕亮度,关闭屏幕
- Android中JNI的使用方法
- 【iOS学习笔记 15-11-06】简单自定义navigationcontroller push和pop动画效果
- 我的iOS学习历程 - OC第九天
- 我的iOS学习历程 - OC第九天
- ios多线程死锁解析