系统功能 比如打电话…
权限
<!--打电话权限-->
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<!--相机-->
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<!--读写SD卡-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
//打电话
private void Call() {
Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:12346789"));
startActivity(intent);
}
//浏览器
private void Broswer() {
Intent intent=new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.douyu.com/directory/myFollow"));
startActivity(intent);
//录制
btVideo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent();
intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);//视频录制
startActivityForResult(intent,100);
}
});
if (requestCode==100&&resultCode== Activity.RESULT_OK){
Uri data1 = data.getData();
vv.setVideoURI(data1);
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
vv.start();
}
});
}
//截图
btJietu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO 1:获得窗体View
View decorView = getWindow().getDecorView();
//TODO 2:设置允许缓存:Cache
decorView.setDrawingCacheEnabled(true);
//TODO 3:构建一次缓存
decorView.buildDrawingCache();
//TODO 4:获得缓存的图片
Bitmap drawingCache = decorView.getDrawingCache();
//TODO 6:截图保存到SD卡中
try {
//参数一 图片的格式 参数二 质量 0-100 参数三 输出流SD卡
drawingCache.compress(Bitmap.CompressFormat.JPEG,100,new FileOutputStream("/sdcard/www.jpg"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
});
//图库
btPick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent();
intent.setAction(Intent.ACTION_PICK);//PICK 选择
intent.setType("image/*");//设置类型,只要图片
startActivityForResult(intent,101);
}
});
else if (requestCode==101&&resultCode==Activity.RESULT_OK){
Uri data1 = data.getData();
System.out.println(data1);
Glide.with(this)
.load(data1)
.transform(new CircleCrop())
.into(iv);
}
相机
清单文件
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.day10_quanxian"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/zhaopiao" />
</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>
</paths>
方法
String apath;
private void xiangji() {
Intent intent=new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);//图片录制
apath="/sdcard/DCIM/"+pathname();
Uri uriForFile = FileProvider.getUriForFile(this, "com.example.day10_quanxian", new File(apath));
intent.putExtra(MediaStore.EXTRA_OUTPUT,uriForFile);
startActivityForResult(intent,103);
}
public String pathname(){
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
String format = simpleDateFormat.format(date);
return "Amg"+format+".jpg";
}
else if (requestCode==103&&resultCode==Activity.RESULT_OK){
System.out.println(apath);
Log.i(TAG, "onActivityResult:====================== "+apath);
Glide.with(this).load(apath)//SD卡文件路径
.transform(new CircleCrop())
.into(iv);
Uri uri = Uri.fromFile(new File(pathname()));
Intent intent=new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(uri);
sendBroadcast(intent);
}