package com.bw.zhuangao2_10;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import androidx.viewpager.widget.ViewPager;
import android.Manifest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import android.widget.VideoView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class MainActivity extends AppCompatActivity {
private ImageView im1;
private VideoView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
im1 = (ImageView) findViewById(R.id.im1);
view = (VideoView) findViewById(R.id.view);
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
requestPermissions(new String[]{
Manifest.permission.CALL_PHONE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
},101);
}
}
public void openborwer(View view) {//打开浏览器
Intent intent=new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri=Uri.parse("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fbbd1a13c-5da1-4a52-92b6-e5bfc0426a25%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1688021164&t=60730df7d552944d876ade8d576148c9");
intent.setData(uri);
startActivity(intent);
}
public void callphone(View view) {//打电话
Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
Uri uri=Uri.parse("tel:"+"18643861186");
intent.setData(uri);
startActivity(intent);
}
public void capture(View view) {//截图
View dectorview=getWindow().getDecorView();
//1设置缓存
dectorview.setDrawingCacheEnabled(true);
//2截图
dectorview.buildDrawingCache();
//3获取截图
Bitmap bitmap=dectorview.getDrawingCache();
im1.setImageBitmap(bitmap);
try {
bitmap.compress(Bitmap.CompressFormat.PNG,100,new FileOutputStream("/sdcard/DCIM/sy.png"));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
public void changimage(View view) {//更换头像
Intent intent=new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent,102);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==102&&resultCode==RESULT_OK){
Uri uri=data.getData();
im1.setImageURI(uri);
}
if(requestCode==202&&resultCode==RESULT_OK){
Uri uri=data.getData();
view.setVideoURI(uri);
}
if(requestCode==400&&resultCode==RESULT_OK){
im1.setImageBitmap(BitmapFactory.decodeFile("/sdcard/DCIM.guo.jp"));
}
}
public void openCamera(View view) {
Intent intent=new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,202);
}
public void openPhoto(View view) {//打开照相机
Intent intent=new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
Uri uri= FileProvider.getUriForFile(this,"com.bw.fp",new File("/sdcard/DCIM.guo.jp"));
intent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
startActivityForResult(intent,400);
}
}
专高2-day10----权限
最新推荐文章于 2024-08-23 11:30:03 发布