截图
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 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>