private ImageView imageView;
VideoView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestPermissions(new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.READ_CONTACTS,
Manifest.permission.WRITE_CONTACTS,
Manifest.permission.READ_SMS,
Manifest.permission.CALL_PHONE,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WRITE_CALL_LOG,
Manifest.permission.READ_CALL_LOG
},101);
imageView=findViewById(R.id.img);
view=findViewById(R.id.aa);
}
public void onClick(View view) {
//打开网络
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri=Uri.parse("https://cn.bing.com/search?q=%E5%93%88%E5%93%88&form=ANSPH1&refig=98db084ff01a4db2bff25358d4ee400f&pc=EdgeStart");
intent.setData(uri);
startActivity(intent);
}
//拨打电话
public void onClick1(View view) {
Intent intent = new Intent();
intent.setAction(intent.ACTION_CALL);
Uri uri=Uri.parse("tel:"+"17861721709");
intent.setData(uri);
startActivity(intent);
Toast.makeText(this, "拨打成功", Toast.LENGTH_SHORT).show();
}
//截图
public void onClick2(View view) {
View decorView = getWindow().getDecorView();
//设置缓存
decorView.setDrawingCacheEnabled(true);
//截图
decorView.buildDrawingCache();
//获取截图
Bitmap bitmap=decorView.getDrawingCache();
imageView.setImageBitmap(bitmap);
try {
//把截图发进sd卡
bitmap.compress(Bitmap.CompressFormat.PNG,100,new FileOutputStream("/sdcard/Ringtones/ji.jpg"));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
//打开相册
public void onClick3(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent,101);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==101||resultCode==RESULT_OK);
Uri uri=data.getData();
imageView.setImageURI(uri);
}
//打开摄像头
public void onClick4(View view) {
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,202);
}
@Override
public void onActivityReenter(int resultCode, Intent data) {
super.onActivityReenter(resultCode, data);
if (resultCode==101&&resultCode==RESULT_OK){
Uri uri = data.getData();
imageView.setImageURI(uri);
}
if (resultCode==202&&resultCode==RESULT_OK){
Uri uri = data.getData();
view.setVideoURI(uri);
view.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
view.start();
}
});
}
//
}
网络,拨打电话,打开相机相册权限
于 2023-06-29 09:12:23 首次发布