android应用中使用相机功能,大体有两种方式实现:html
若是须要拍照功能,则须要在AndroidManifest.xml文件中添加权限:android
<uses-permission android:name="android.permission.CAMERA"/>
这是第一种方式
在启动相机前先指定好图片的文件位置,通知intent,同时也保留在成员变量中。而后在函数中,能够直接打开该文件app
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);
获取返回值ide
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中得到选择的图片.net
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); }
android.intent.action.CALL
呼叫指定的电话号码。code
Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:10086"); startActivity(intent);
String: action.intent.action.DIAL
调用拨号面板
Intent intent=new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:10086");
startActivity(intent);xml
String: andriod.intent.action.ALL_APPS
列出全部的应用。htm
String:android.intent.action.CALL_PRIVILEGED
调用skype的actionblog
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);
String: android.action.intent.CALL_BUTTON.
至关于按“拨号”键。
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
startActivity(intent);
String: android.provider.Telephony.SMS_RECEIVED
接收短信的action
String: android.intent.action.GET_CONTENT
容许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)
String: android.intent.action.BATTERY_LOW
表示电池电量低
String: android.intent.action.Send
发送邮件的action
当屏幕超时进行锁屏时,当用户按下电源按钮,长按或短按(无论有没跳出话框),进行锁屏时,android系统都会广播此Action消息
String: android.intent.action.MAIN
标识Activity为一个程序的开始。
插上外部电源时发出的广播
已断开外部电源链接时发出的广播
Stirng:android.intent.action.ANSWER
处理呼入的电话。
String: android.intent.action.BUG_REPORT
显示Dug报告。
action的操做有不少,须要的话,继续百度。