Android调用手机系统资源

打开图片,打开音乐,打开视频,安装应用等等。。

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;

import java.io.File;

public class IntentActivity extends AppCompatActivity {

    private String capturePath;
    private final int TAKE_PHOTO=0;
    private final int RESULT_PHOTO=2;
    private  final int PHONE_PHOTO=1;
    private RoundImageView riv;
    private PopupWindow popupWindow;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent);

        Button bt1=(Button)findViewById(R.id.bt1);
        Button bt2=(Button)findViewById(R.id.bt2);
        Button bt3=(Button)findViewById(R.id.bt3);
        Button bt4=(Button)findViewById(R.id.bt4);
        Button bt5=(Button)findViewById(R.id.bt5);
        Button bt6=(Button)findViewById(R.id.bt6);
        riv=(RoundImageView)findViewById(R.id.riv);

        View view=getLayoutInflater().inflate(R.layout.pop_layout,null);
        popupWindow=new PopupWindow(view);
        popupWindow.setFocusable(true);
        ColorDrawable cd=new ColorDrawable();
        popupWindow.setBackgroundDrawable(cd);

        Button bt_Camera= (Button) view.findViewById(R.id.bt_camera);
        Button bt_Photo= (Button) view.findViewById(R.id.bt_photo);
        Button bt_qx= (Button) view.findViewById(R.id.bt_qx);
        bt_Camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //调用相机
                Intent camera=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File parent=FileUitlity.getInstance(getApplicationContext()).makeDir("head_img");
                capturePath=parent.getPath()+File.separatorChar+System.currentTimeMillis()+".jpg";
                camera.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(capturePath)));
                camera.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,1);
                startActivityForResult(camera,TAKE_PHOTO);
                popupWindow.dismiss();
            }
        });
        bt_Photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //调用相册
                phone_photo();
                popupWindow.dismiss();
            }
        });
        bt_qx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        //拨打电话到1008611
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri=Uri.parse("tel:1008611");
                Intent it=new Intent(Intent.ACTION_DIAL,uri);
                startActivity(it);
            }
        });

        //发送短信到1008611
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri=Uri.parse("smsto:10086");
                Intent it=new Intent(Intent.ACTION_SENDTO,uri);
                it.putExtra("sms_body","代开发票");
//                it.setType("vnd.android-dir/mns-sms");
                startActivity(it);
            }
        });

        //打开网页
        bt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri=Uri.parse("http://www.baidu.com");
                Intent it=new Intent(Intent.ACTION_VIEW,uri);
                startActivity(it);
            }
        });

        //打开图片
        bt4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent(Intent.ACTION_VIEW);
                File file=new File("图片地址");
                it.setDataAndType(Uri.fromFile(file),"image/*");
                startActivity(it);
            }
        });

        //打开音乐
        bt5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent(Intent.ACTION_VIEW);
                File file=new File("mp3地址");
                it.setDataAndType(Uri.fromFile(file),"audio/*");
                startActivity(it);
            }
        });

        //安装应用
        bt6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent(Intent.ACTION_VIEW);
                it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                it.setDataAndType(Uri.parse("file:///sdcard/abc.apk"),"application/vnd.android.package-archive");
                startActivity(it);
            }
        });

private void openVideo(){
    //打开视频
        Intent it=new Intent(Intent.ACTION_VIEW);
                            File file=new File("视频地址");
                            it.setDataAndType(Uri.fromFile(file), "video/mp4");
                            startActivity(it);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值