Android Intent Usage Comprehensive summary (reprint)

Source: Internet
Author: User

1. [Code] Call dialer
1234 // 给移动客服10086拨打电话Uri uri = Uri.parse("tel:10086");Intent intent = newIntent(Intent.ACTION_DIAL, uri);startActivity(intent);
2. [Code] send SMS or MMS
123456789101112 // 给10086发送内容为“Hello”的短信Uri uri = Uri.parse("smsto:10086");Intent intent = new Intent(Intent.ACTION_SENDTO, uri);intent.putExtra("sms_body", "Hello");startActivity(intent);// 发送彩信(相当于发送带附件的短信)Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra("sms_body", "Hello");Uri uri = Uri.parse("content://media/external/images/media/23");intent.putExtra(Intent.EXTRA_STREAM, uri);intent.setType("image/png");startActivity(intent);
3. [Code] open Web page via browser
1234 // 打开Google主页Uri uri = Uri.parse("http://www.google.com");Intent intent  = newIntent(Intent.ACTION_VIEW, uri);startActivity(intent);
4. [Code] send e-mail
1234567891011121314151617181920212223 // 给[email protected]发邮件Uri uri = Uri.parse("mailto:[email protected]");Intent intent = new Intent(Intent.ACTION_SENDTO, uri);startActivity(intent);// 给[email protected]发邮件发送内容为“Hello”的邮件Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");intent.putExtra(Intent.EXTRA_TEXT, "Hello");intent.setType("text/plain");startActivity(intent);// 给多人发邮件Intent intent=new Intent(Intent.ACTION_SEND);String[] tos = {"[email protected]", "[email protected]"}; // 收件人String[] ccs = {"[email protected]", "[email protected]"}; // 抄送String[] bccs = {"[email protected]", "[email protected]"}; // 密送intent.putExtra(Intent.EXTRA_EMAIL, tos);intent.putExtra(Intent.EXTRA_CC, ccs);intent.putExtra(Intent.EXTRA_BCC, bccs);intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");intent.putExtra(Intent.EXTRA_TEXT, "Hello");intent.setType("message/rfc822");startActivity(intent);
5. [Code] show map and path planning
12345678 // Open Google Maps China Beijing location (latitude 39.9, longitude 116.3) uri Uri = Uri.parse ( "geo:39.9,116.3" intent Intent = new intent (Intent.action_view, URI); startactivity (intent); //path planning: From Somewhere in Beijing (latitude 39.9, longitude 116.3) to a place in Shanghai (latitude 31.2, longitude 121.4) uri Uri = Uri.parse ( " Http://maps.google.com/maps?f=d &saddr=39.9 116.3&daddr=31.2 121.4 " ); intent Intent = new intent (Intent.action_view, URI); startactivity (intent);
6. [code] Play multimedia     
12345678 intent Intent = new intent (intent.action_view); uri Uri = Uri.parse ( Code class= "Java Plain"); intent.setdataandtype (URI, startactivity (intent);  uri Uri = Uri.withappendedpath (MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1" intent Intent = new intent (Intent.action_view, URI); startactivity (intent);
7. [Code] take photos
123456 // 打开拍照程序Intent intent = newIntent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 0);// 取出照片数据Bundle extras = intent.getExtras(); Bitmap bitmap = (Bitmap) extras.get("data");
8. [Code] get and cut pictures
1234567891011121314151617181920212223 // 获取并剪切图片Intent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType("image/*");intent.putExtra("crop", "true"); // 开启剪切intent.putExtra("aspectX", 1); // 剪切的宽高比为1:2intent.putExtra("aspectY", 2);intent.putExtra("outputX", 20); // 保存图片的宽和高intent.putExtra("outputY", 40); intent.putExtra("output", Uri.fromFile(new File("/mnt/sdcard/temp"))); // 保存路径intent.putExtra("outputFormat", "JPEG");// 返回格式startActivityForResult(intent, 0);// 剪切特定图片Intent intent = new Intent("com.android.camera.action.CROP"); intent.setClassName("com.android.camera", "com.android.camera.CropImage"); intent.setData(Uri.fromFile(new File("/mnt/sdcard/temp"))); intent.putExtra("outputX", 1); // 剪切的宽高比为1:2intent.putExtra("outputY", 2);intent.putExtra("aspectX", 20); // 保存图片的宽和高intent.putExtra("aspectY", 40);intent.putExtra("scale", true);intent.putExtra("noFaceDetection", true); intent.putExtra("output", Uri.parse("file:///mnt/sdcard/temp")); startActivityForResult(intent, 0);
9. [Code] Open Google Market
1234 // 打开Google Market直接进入该程序的详细页面Uri uri = Uri.parse("market://details?id="+ "com.demo.app");Intent intent = newIntent(Intent.ACTION_VIEW, uri);startActivity(intent);
10. [Code] install and uninstall programs
123 Uri uri = Uri.fromParts("package", "com.demo.app", null);  Intent intent = newIntent(Intent.ACTION_DELETE, uri);  startActivity(intent);
11. [Code] into the setup screen
123 // 进入无线网络设置界面(其它可以举一反三)  Intent intent = newIntent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);  startActivityForResult(intent, 0);

Android Intent Usage Comprehensive summary (reprint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.