Android 拍照以及一些常用的处理,例如将图片显示到相册(包含了安卓系统6.0以上调用相机的处理)

/**

* 方法一:最简单的拍照,但是拍摄的会比较模糊 ,是因为系统默认给我们的图片进行了压缩

*@paramview

*/

public void_camera1(View view) {

try{

Intent intent =newIntent(MediaStore.ACTION_IMAGE_CAPTURE);//拍照意图

startActivityForResult(intent,CAMERA_1_REQUEST);

}catch(RuntimeException e) {//用来捕获6.0后调用系统相机给了权限但是还是会崩的问题

Toast.makeText(this,"请打开手机中该软件的调用系统相机的权限",Toast.LENGTH_SHORT).show();

//跳转提示用户打开该软件调用相机的权限

Intent intent =newIntent();

intent.setAction("android.intent.action.MAIN");

intent.setClassName("com.android.settings","com.android.settings.ManageApplications");

startActivity(intent);

}

}

下面两种方式我就不再做6.0权限的跳转请求了


//第二种自定义路径的拍照但是在系统的相册中不能看到图片

public void_Camera02(View view) {

//确认意图 跳转到相机

Intent intent =newIntent(MediaStore.ACTION_IMAGE_CAPTURE);

//存储路径

String path = Environment.getExternalStorageDirectory().getAbsolutePath() +"/CD1603";

File file =newFile(path);

if(!file.exists()){

Log.e(TAG,"mkdirs");

file.mkdirs();

}

String name = System.currentTimeMillis() +".jpg";

path = path +"/"+ name;

Log.e(TAG,"path:"+path);

mFile=newFile(path);

//告知相机 保存到哪

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mFile));

//

startActivityForResult(intent,CAMERA02);

}

//第三种拍照自定义路径并通知系统相册刷新相册(显示在相册中)

public void_Camera03(View view) {

ContentValues values =newContentValues();

//文件名称

values.put(MediaStore.Images.Media.DISPLAY_NAME,System.currentTimeMillis()+".jpg");

values.put(MediaStore.Images.Media.MIME_TYPE,"image/png");

//存入数据库

mPathUri= getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

Intent intent =newIntent(MediaStore.ACTION_IMAGE_CAPTURE);

intent.putExtra(MediaStore.EXTRA_OUTPUT,mPathUri);

//注:这句话建议放到onActivityResult回调之后刷新相册

//广播通知系统 刷新数据库,将我们存储的位置保存到数据库

sendBroadcast(newIntent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(mFile)));

startActivityForResult(intent,CAMERA03);

}

注:该跳转方式只能跳转到系统权限设置不能跳到指定的app权限设置,如果大家有方法请提出修改建议(据说小米系统可以做到这个我也看了相关的方法,但是没必要写出来了,因为它只局限小米)




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/* * 基于双向链表实现双端队列结构 */ package dsa; public class Deque_DLNode implements Deque { protected DLNode header;//指向头节点(哨兵) protected DLNode trailer;//指向尾节点(哨兵) protected int size;//队列中元素的数目 //构造函数 public Deque_DLNode() { header = new DLNode(); trailer = new DLNode(); header.setNext(trailer); trailer.setPrev(header); size = 0; } //返回队列中元素数目 public int getSize() { return size; } //判断队列是否为空 public boolean isEmpty() { return (0 == size) ? true : false; } //取首元素(但不删除) public Object first() throws ExceptionQueueEmpty { if (isEmpty()) throw new ExceptionQueueEmpty("意外:双端队列为空"); return header.getNext().getElem(); } //取末元素(但不删除) public Object last() throws ExceptionQueueEmpty { if (isEmpty()) throw new ExceptionQueueEmpty("意外:双端队列为空"); return trailer.getPrev().getElem(); } //在队列前端插入新节点 public void insertFirst(Object obj) { DLNode second = header.getNext(); DLNode first = new DLNode(obj, header, second); second.setPrev(first); header.setNext(first); size++; } //在队列后端插入新节点 public void insertLast(Object obj) { DLNode second = trailer.getPrev(); DLNode first = new DLNode(obj, second, trailer); second.setNext(first); trailer.setPrev(first); size++; } //删除首节点 public Object removeFirst() throws ExceptionQueueEmpty { if (isEmpty()) throw new ExceptionQueueEmpty("意外:双端队列为空"); DLNode first = header.getNext(); DLNode second = first.getNext(); Object obj = first.getElem(); header.setNext(second); second.setPrev(header); size--; return(obj); } //删除末节点 public Object removeLast() throws ExceptionQueueEmpty { if (isEmpty()) throw new ExceptionQueueEmpty("意外:双端队列为空"); DLNode first = trailer.getPrev(); DLNode second = first.getPrev(); Object obj = first.getElem(); trailer.setPrev(second); second.setNext(trailer); size--; return(obj); } //遍历 public void Traversal() { DLNode p = header.getNext(); while (p != trailer) { System.out.print(p.getElem()+" "); p = p.getNex
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值