废话不多说 程序贴上

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

<Button android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/open_camera"
        android:id="@+id/openCamera"/>
    
    <TextView android:id="@+id/phone_call"
        android:text="@string/make_call"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:autoLink="phone"
        android:background="@android:color/white"/>
    
    <TextView android:id="@+id/web_open"
        android:text="@string/make_web"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:autoLink="web"
        android:background="@android:color/white"/>
    
    <ImageView android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/cameraImage"
        android:contentDescription="@string/open_camera"/>    
    
</LinearLayout>

package com.yunfeng.bus;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.kobjects.base64.Base64;

import com.yunfeng.bus.dao.ImageUploadDao;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class SaySelfActivity extends Activity implements OnClickListener{
private Button openCamera;
private ImageView cameraImage;
private TextView phoneText;

final int RESULT_LOAD_IMAGE = 0;//表示打开系统图库
final int TAKE_PICTURE = 1;//为了表示返回方法中辨识你的程序打开的相机

private Bitmap myBitmap;
private byte[] mContent;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.say_self);
openCamera = (Button)findViewById(R.id.openCamera);
cameraImage = (ImageView)findViewById(R.id.cameraImage);
phoneText = (TextView)findViewById(R.id.phone_call);

phoneText.setOnClickListener(this);
openCamera.setOnClickListener(this);
}

public void onClick(View v) {
int id = v.getId();
switch(id){
case R.id.phone_call:
/*
* 隐藏的方法是直接拨打电话 用autoink为将电话拨打状态  
*/
//Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"));
//startActivity(intent);
break;
case R.id.openCamera:{
final CharSequence[] items =
{ "相册", "拍照" };
AlertDialog dlg = new AlertDialog.Builder(SaySelfActivity.this).setTitle("选择图片").setItems(items,
new DialogInterface.OnClickListener()
{
public void onClick ( DialogInterface dialog , int item )
{
// 这里item是根据选择的方式,
// 在items数组里面定义了两种方式,拍照的下标为1所以就调用拍照方法
if (item == 1){
Intent getImageByCamera = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(getImageByCamera, TAKE_PICTURE);
} else{
Intent getImage = new Intent(Intent.ACTION_GET_CONTENT);
getImage.addCategory(Intent.CATEGORY_OPENABLE);
getImage.setType("image/jpeg");
startActivityForResult(getImage, 0);
}
}
}).create();
dlg.show();
}
break;
}
}

protected void onActivityResult ( int requestCode , int resultCode , Intent data )
{
super.onActivityResult(requestCode, resultCode, data);

ContentResolver resolver = getContentResolver();
/**
* 因为两种方式都用到了startActivityForResult方法,
* 这个方法执行完后都会执行onActivityResult方法, 所以为了区别到底选择了那个方式获取图片要进行判断,
* 这里的requestCode跟startActivityForResult里面第二个参数对应
*/
if (requestCode == RESULT_LOAD_IMAGE)
{
try
{
Log.v("how", "jhhh");
// 获得图片的uri
Uri originalUri = data.getData();
// 将图片内容解析成字节数组
mContent = readStream(resolver.openInputStream(Uri.parse(originalUri.toString())));
Log.v("byte", String.valueOf(mContent));
// 将字节数组转换为ImageView可调用的Bitmap对象
myBitmap = getPicFromBytes(mContent, null);
//上传图片

// //把得到的图片绑定在控件上显示
cameraImage.setImageBitmap(myBitmap);

String result = null;
ImageUploadDao dao = new ImageUploadDao();
result = dao.getImage(mContent);

phoneText.setText(result);
} catch ( Exception e ){
System.out.println(e.getMessage());
}

} if (resultCode == TAKE_PICTURE) {
            Bitmap bm = (Bitmap) data.getExtras().get("data");
            cameraImage.setImageBitmap(bm);//想图像显示在ImageView视图上,private ImageView img;
            File myCaptureFile = new File("sdcard/123456.jpg");
            try {                
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
            /* 采用压缩转档方法 */
            bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
       
            /* 调用flush()方法,更新BufferStream */
            bos.flush();
       
            /* 结束OutputStream */
            bos.close();
            } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
 
            } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            }
        }
}

public static Bitmap getPicFromBytes ( byte[] bytes , BitmapFactory.Options opts )
{
if (bytes != null)
if (opts != null)
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, opts);
else
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
return null;
}

public static byte[] readStream ( InputStream inStream ) throws Exception
{
byte[] buffer = new byte[1024];
int len = -1;
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
while ((len = inStream.read(buffer)) != -1)
{
outStream.write(buffer, 0, len);
}
byte[] data = outStream.toByteArray();
outStream.close();
inStream.close();
return data;
}
}

android调用系统图库及系统照相机,打电话相关推荐

  1. Android 调用相册 拍照 实现系统控件缩放 切割图片

    android 下如果做处理图片的软件 可以调用系统的控件 实现缩放切割图片 非常好的效果 今天写了一个demo分享给大家. package cn.m15.test;import java.io.By ...

  2. Android调用手机图库选择图片并调用手机的图片裁剪工具

    /*** 获得图库图片回调标识*/public static final int GET_PIC_FROM_GALLERY = 0X100;/*** 调用手机工具编辑图片标识*/public stat ...

  3. Android nomedia 避免图片等资源泄露在系统图库其中

    总结 Android nomedia 避免文件泄露在系统图库和系统铃声中 在应用开发中 项目的图片总是被系统的图库收录了 避免图片被系统图库收录的发现有2个方法 第一种针对图片 将 .png为后缀的图 ...

  4. Android nomedia 避免图片等资源泄露在系统图库当中

    总结 Android nomedia 避免文件泄露在系统图库和系统铃声中 在应用开发中 项目的图片总是被系统的图库收录了 避免图片被系统图库收录的发现有2个方法 第一种针对图片 将 .png为后缀的图 ...

  5. android 调用系统的照相机和图库

    android手机有自带的照相机和图库,我们做的项目中有时用到上传图片到服务器,今天做了一个项目用到这个功能,所以把我的代码记录下来和大家分享,第一次写博客希望各位大神多多批评. 首先上一段调用and ...

  6. 直播网站源码,Android调用系统照相机和摄像机

    直播网站源码,Android调用系统照相机和摄像机实现的相关代码 private void callPhone() {//获得文件File _file = new File(StorageUtils. ...

  7. android 图库管理,Android调用系统图库

    上面一篇讲到Android调用系统相机时遇到的兼容性问题,没想到选择系统图库的时候竟然也遇到了系统兼容性问题,在这里记录下解决方案吧. 首先是调用系统默认图库代码: Intent intent = n ...

  8. Android 调用系统照相机拍照和录像

    Android 调用系统照相机拍照和录像 项目的布局相当简单,只有一个Button: <RelativeLayout xmlns:android="http://schemas.and ...

  9. Android开发:调用系统图库选择图片

    方法: //调用系统图库选择图片 public Intent selectPicture() {Intent intent = new Intent(Intent.ACTION_PICK,androi ...

最新文章

  1. 《大数据、小数据、无数据:网络世界的数据学术》一 导读
  2. mysql replace语句
  3. 我思故我在之编程规范及编程思想篇
  4. 动手写一个快速集成网易新闻,腾讯视频,头条首页的ScrollPageView,显示滚动视图...
  5. Java和ABAP中的几种引用类型的分析和比较
  6. BOM中的那点事-location
  7. [cerc2012][Gym100624B]20181013
  8. 国外一教授坦言,用这方法能迅速成为python程序员,但都不愿意说
  9. Java 失宠于 Oracle?
  10. 倾角传感器原理及市场现状浅析
  11. 一、阿里矢量图标(字体图标)
  12. 基础篇:深入解析JAVA注解机制
  13. Efficient Protocols for Set Membership and Range Proof 学习笔记
  14. 强化学习之贝尔曼方程
  15. 第七届蓝桥杯 2016年省赛真题(Java 大学C组)
  16. vue3之常范低级错误の错误指南
  17. 如何设置计划任务程序 每6小时运行一次_如何用 Python 打造一个全自动赚钱的 YouTube 视频发布系统并月入过万(被动收益)
  18. 使用虚拟主机安装cyberpanel面板并创建wordpress站点
  19. 学习Java虚拟机的正确的姿势?
  20. pycharm 中引用airtest中的air 文件

热门文章

  1. java web打开文件_Java web 如何打开本地文件夹?
  2. excel 第8讲:if函数逻辑判断
  3. Linux系统用户/组管理
  4. linux系统中插件安装失败,Ubuntu 安装Rhythmbox多媒体插件时出现错误
  5. 变频电源不同方式的分类
  6. 基本初等函数 指数函数
  7. 1256:献给阿尔吉侬的花束 2021-01-09
  8. 大家都在拼命进大厂,就我偏偏往二线跑
  9. SpringBoot的文件下载
  10. SQL yog解除30天试用限制