实现功能:相机+摄像+浏览器+打电话+截屏
权限
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.CAMERA"/>
使用隐式意图打开浏览器
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri parse = Uri.parse("https://www.baidu.com/");
intent.setData(parse);
startActivity(intent);
使用隐式意图打电话
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
Uri parse = Uri.parse("tel:"+"1008611");
intent.setData(parse);
startActivity(intent);
截图
View decorView = getWindow().getDecorView();
decorView.setDrawingCacheEnabled(true);
Bitmap drawingCache = decorView.getDrawingCache();
picId.setImageBitmap(drawingCache);
try {
drawingCache.compress(Bitmap.CompressFormat.PNG,100,new FileOutputStream("/mnt/sdcard/aa.png"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
照相机+FileProvider
清单文件注册FileProvider
<provider
android:authorities="hehe"
android:name="android.support.v4.content.FileProvider"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/fileprobider"/>
</provider>
创建文件路径
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external_storage_root"
path="."></external-path>
</paths>
使 Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File("/mnt/sdcard/hehe.png");
Uri uriForFile = FileProvider.getUriForFile(MainActivity.this, "hehe", file);
intent.putExtra(MediaStore.EXTRA_OUTPUT,uriForFile);
startActivity(intent);用FileProvider将照片保存到SD卡中
摄像机
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent,100);
回
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && requestCode == RESULT_OK){
Uri data1 = data.getData();
}
}
*剩余代码详细效果请看手机 ![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0c9548f3c566cafdf32bc958dd6bd3e4.png)