Intent : 打开网址
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.baidu.com");
intent.setData(uri);
tartActivity(intent);
Intent : 拨号
Intent myIntent = new Intent();
Uri uri = Uri.parse("tel:123456");
myIntent.setAction(Intent.ACTION_DIAL);
myIntent.setData(uri);
startActivity(myIntent);
Intent:打电话
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
Uri uri = Uri.parse("tel:123445");
intent.setData(uri);
startActivity(intent);
Intent : 启动相册
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,100);
Intent: 打开相机
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent,200);
Intent: 打开相册图片
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK); intent.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI,"image/*");
startActivityForResult(intent,300);
Intent : 打开录音
Intent intent = new Intent();
intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivity(intent);
上面的系统回调返回
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 100 && resultCode == Activity.RESULT_OK) {
Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap) bundle.get("data");
ImageView tupian = (ImageView) findViewById(R.id.tupian);
tupian.setImageBitmap(Bitmap.createBitmap(bitmap));
}
if (requestCode == 200 && resultCode == Activity.RESULT_OK) {
String s = data.getData().toString();
Toast.makeText(MainActivity.this, "视频保存在" + s, Toast.LENGTH_SHORT).show();
}
if (requestCode == 300 && resultCode == Activity.RESULT_OK) {
ImageView iv = (ImageView) findViewById(R.id.opentupain);
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
iv.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}