打开浏览器,拨打电话,截图,打开相册,打开摄像机

权限

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CALL_PHONE"/>
    <uses-permission android:name="android.permission.CAMERA"/>

动态权限

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);
<Button
        android:text="打开浏览器"
        android:onClick="openBrow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <Button
        android:text="拨打电话"
        android:onClick="dissuade"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <Button
        android:text="截图"
        android:onClick="chapter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <Button
        android:text="打开相册"
        android:onClick="openPho"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <Button
        android:text="打开摄像机"
        android:onClick="openCamera"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <ImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="200dp"/>
    <VideoView
        android:id="@+id/vv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
public void openBrow(View view) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.parse("https://www.baidu.com/s?ie=utf-8&wd=%E7%99%BE%E5%BA%A6&tn=62076830_13_hao_pg");
        intent.setData(uri);
        startActivity(intent);

    }

    //拨打电话
    public void dissuade(View view) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_CALL);
        Uri uri = Uri.parse("tel:"+"17861721709");
        intent.setData(uri);
        startActivity(intent);
    }

    //截图
    public void chapter(View view) {
        View decorView = getWindow().getDecorView();
        //设置缓存
        decorView.setDrawingCacheEnabled(true);
        //截图
        decorView.buildDrawingCache();
        //获取截图
        Bitmap bitmap = decorView.getDrawingCache();
        img.setImageBitmap(bitmap);
        try {
            bitmap.compress(Bitmap.CompressFormat.PNG,100,new FileOutputStream("/sdcard/DCIM/ji.png"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }


    //打开相册
    public void openPho(View view) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(intent,101);
    }

    //打开摄像机
    public void openCamera(View view) {
        Intent intent = new Intent();
        intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
        startActivityForResult(intent,202);

    }
    @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();
            img.setImageURI(uri);
        }
        if (requestCode==202&&resultCode==RESULT_OK){
            Uri uri = data.getData();
            videoView.setVideoURI(uri);
            videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    videoView.start();
                }
            });
        }
        if (requestCode==404&&resultCode==RESULT_OK){
            img.setImageURI(uri);
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值