安卓02照相机等的操作

截图

 case R.id.jt:
                View decorView = getWindow().getDecorView();
                decorView.setDrawingCacheEnabled(true);//设置可以被缓存
                decorView.buildDrawingCache();//缓存




                Bitmap bitmap = decorView.getDrawingCache();
                Date date = new Date();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYYMMdd-hhmmss");
                String format = simpleDateFormat.format(date.getTime());
                String s = "/sdcard/DCIM/Camera/" + format + ".jpg";
                try {
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(s));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                MediaStore.Images.Media.insertImage(getContentResolver(),bitmap,"图片的标识","图片的描述");
                main_image.setImageBitmap(bitmap);
                break;

打电话

 case R.id.tele:
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + "17625049232"));
                startActivity(intent);
                break;

打开浏览器

case R.id.llq:
                Intent intent1 = new Intent();
                intent1.setAction(Intent.ACTION_VIEW);
                intent1.setData(Uri.parse("https://mp.csdn.net/postlist"));
                startActivity(intent1);
                break;

打开摄像机录像并保存

 case R.id.sxj:
                Intent sxjaa = new Intent();
                sxjaa.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
                startActivityForResult(sxjaa,101);
                break;

打开照相机不能自动保存创建清单文件和xml文件保存到指定的地址

 case R.id.zxj:
                Intent zxjaa = new Intent();
                zxjaa.setAction(MediaStore.ACTION_IMAGE_CAPTURE);




                Date date1 = new Date();
                SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("YYYYMMdd-hhmmss");
                String format1 = simpleDateFormat1.format(date1.getTime());






                File file = new File("/sdcard/DCIM/Camera/"+format1+".jpg");
                uriForFile = FileProvider.getUriForFile(MainActivity.this, "com.yyh", file);
                zxjaa.putExtra(MediaStore.EXTRA_OUTPUT,uriForFile);


                startActivityForResult(zxjaa,102);
                break;
//清单文件
 <provider
            android:exported="false"
            android:authorities="com.yyh"
            android:grantUriPermissions="true"
            android:name="androidx.core.content.FileProvider">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/xmlaaa"></meta-data>


        </provider>
//需要存入的xml地址
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path
        name="mypath"
        path="DCIM">
    </external-path>


    <external-path
        name="mypath1"
        path="Camera"></external-path>


</paths>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值