隐示意图

package com.example.camrea;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;

import android.Manifest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";
private Button mInternet;
private Button mCamera;
private Button mPhone;
private Button mVedio;
private Button mJietu;
private ImageView mImage;
private Uri uriForFile;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

    if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.M){
        requestPermissions(new String[]{
                Manifest.permission.CALL_PHONE,
                Manifest.permission.CAMERA,
                Manifest.permission.INTERNET,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE
        },110);
    }

    initView();

}

private void initView() {
    mInternet = findViewById(R.id.internet);
    mCamera = findViewById(R.id.camera);
    mPhone = findViewById(R.id.phone);
    mVedio = findViewById(R.id.vedio);
    mJietu = findViewById(R.id.jietu);
    mImage = findViewById(R.id.image);
}

public void click(View view) {
    switch (view.getId()){
        case R.id.camera:
            camera();
            break;
        case R.id.internet:
            internet();
            break;
        case R.id.jietu:
            jietu();
            break;
        case R.id.vedio:
            vedio();
            break;
        case R.id.phone:
            phone();
            break;
    }
}

private void jietu() {
    View decorView = getWindow().getDecorView();
    decorView.setDrawingCacheEnabled(true);
    decorView.buildDrawingCache();
    Bitmap drawingCache = decorView.getDrawingCache();
    mImage.setImageBitmap(drawingCache);


    DateFormat df = new SimpleDateFormat("yyHHmmss");
    String format = df.format(new Date());
    String filePath= "/mnt/sdcard/DCIM/Camera/"+format+".jpg";
    try {
        drawingCache.compress(Bitmap.CompressFormat.JPEG,100,new FileOutputStream(filePath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

private void vedio() {
    Intent intent = new Intent();
    intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
    startActivity(intent);
}

private void camera() {
    Intent intent = new Intent();
    intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
    DateFormat df = new SimpleDateFormat("yyHHmmss");
    String format = df.format(new Date());
    String filePath= "/mnt/sdcard/DCIM/Camera/"+format+".jpg";
    File file = new File(filePath);
    uriForFile = FileProvider.getUriForFile(this, "com.example.camrea.fileProvider", file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,uriForFile);
    startActivityForResult(intent,110);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode==110){
        mImage.setImageURI(uriForFile);
    }
}

private void internet() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.baidu.com/"));
    startActivity(intent);
}

private void phone() {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_CALL);
    intent.setData(Uri.parse("tel:10086"));
    startActivity(intent);
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值