打开图片,打开音乐,打开视频,安装应用等等。。
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);
}
}
}