详细解决方案
Android Intent 用法全面小结
热度:94 发布时间:2016-05-01 15:03:47.0
Android Intent 用法全面总结
代码片段
[代码] 调用拨号程序
2 | Uri uri = Uri.parse( "tel:10086" ); |
3 | Intent intent = new Intent(Intent.ACTION_DIAL, uri); |
[代码] 发送短信或彩信
02 | Uri uri = Uri.parse( "smsto:10086" ); |
03 | Intent intent = new Intent(Intent.ACTION_SENDTO, uri); |
04 | intent.putExtra( "sms_body" , "Hello" ); |
07 | Intent intent = new Intent(Intent.ACTION_SEND); |
08 | intent.putExtra( "sms_body" , "Hello" ); |
09 | Uri uri = Uri.parse( "content://media/external/images/media/23" ); |
10 | intent.putExtra(Intent.EXTRA_STREAM, uri); |
11 | intent.setType( "image/png" ); |
[代码] 通过浏览器打开网
2 | Uri uri = Uri.parse( "http://www.google.com" ); |
3 | Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
[代码] 发送电子邮件
03 | Intent intent = new Intent(Intent.ACTION_SENDTO, uri); |
06 | Intent intent = new Intent(Intent.ACTION_SEND); |
08 | intent.putExtra(Intent.EXTRA_SUBJECT, "Subject" ); |
09 | intent.putExtra(Intent.EXTRA_TEXT, "Hello" ); |
10 | intent.setType( "text/plain" ); |
13 | Intent intent= new Intent(Intent.ACTION_SEND); |
17 | intent.putExtra(Intent.EXTRA_EMAIL, tos); |
18 | intent.putExtra(Intent.EXTRA_CC, ccs); |
19 | intent.putExtra(Intent.EXTRA_BCC, bccs); |
20 | intent.putExtra(Intent.EXTRA_SUBJECT, "Subject" ); |
21 | intent.putExtra(Intent.EXTRA_TEXT, "Hello" ); |
22 | intent.setType( "message/rfc822" ); |
[代码] 显示地图与路径规划
2 | Uri uri = Uri.parse( "geo:39.9,116.3" ); |
3 | Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
6 | Uri uri = Uri.parse( "http://maps.google.com/maps?f=d&saddr=39.9 116.3&daddr=31.2 121.4" ); |
7 | Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
[代码] 播放多媒体
1 | Intent intent = new Intent(Intent.ACTION_VIEW); |
2 | Uri uri = Uri.parse( "file:///sdcard/foo.mp3" ); |
3 | intent.setDataAndType(uri, "audio/mp3" ); |
6 | Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1" ); |
7 | Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
[代码] 拍照
2 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
3 | startActivityForResult(intent, 0 ); |
5 | Bundle extras = intent.getExtras(); |
6 | Bitmap bitmap = (Bitmap) extras.get( "data" ); |
[代码] 获取并剪切图片
02 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT); |
03 | intent.setType( "image/*" ); |
04 | intent.putExtra( "crop" , "true" ); |
05 | intent.putExtra( "aspectX" , 1 ); |
06 | intent.putExtra( "aspectY" , 2 ); |
07 | intent.putExtra( "outputX" , 20 ); |
08 | intent.putExtra( "outputY" , 40 ); |
09 | intent.putExtra( "output" , Uri.fromFile( new File( "/mnt/sdcard/temp" ))); |
10 | intent.putExtra( "outputFormat" , "JPEG" ); |
11 | startActivityForResult(intent, 0 ); |
13 | Intent intent = new Intent( "com.android.camera.action.CROP" ); |
14 | intent.setClassName( "com.android.camera" , "com.android.camera.CropImage" ); |
15 | intent.setData(Uri.fromFile( new File( "/mnt/sdcard/temp" ))); |
16 | intent.putExtra( "outputX" , 1 ); |
17 | intent.putExtra( "outputY" , 2 ); |
18 | intent.putExtra( "aspectX" , 20 ); |
19 | intent.putExtra( "aspectY" , 40 ); |
20 | intent.putExtra( "scale" , true ); |
21 | intent.putExtra( "noFaceDetection" , true ); |
22 | intent.putExtra( "output" , Uri.parse( "file:///mnt/sdcard/temp" )); |
23 | startActivityForResult(intent, 0 ); |
[代码] 打开Google Market
2 | Uri uri = Uri.parse( "market://details?id=" + "com.demo.app" ); |
3 | Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
[代码] 安装和卸载程序
1 | Uri uri = Uri.fromParts( "package" , "com.demo.app" , null ); |
2 | Intent intent = new Intent(Intent.ACTION_DELETE, uri); |
[代码] 进入设置界面
2 | Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); |
3 | startActivityForResult(intent, 0 ); |