English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
1Invoke the dialer program
// To the customer service of mobile10086Make a phone call Uri uri = Uri.parse("tel:");10086"); Intent intent = new Intent(Intent.ACTION_DIAL, uri); startActivity(intent);
2Send SMS or MMS
// To10086Send a text message with the content "Hello" Uri uri = Uri.parse("smsto:");10086"); Intent intent = new Intent(Intent.ACTION_SENDTO, uri); intent.putExtra("sms_body", "Hello"); startActivity(intent); // Send a multimedia message (equivalent to sending an attached SMS) 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);
3By opening a web page in a browser
// Open the Google homepage Uri uri = Uri.parse("http:")//www.google.com\ Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
4. Send email
// Send an email to [email protected] Uri uri = Uri.parse("mailto:[email protected]"); Intent intent = new Intent(Intent.ACTION_SENDTO, uri); startActivity(intent); // Send an email to [email protected] with the content "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); // Send email to multiple recipients Intent intent=new Intent(Intent.ACTION_SEND); String[] tos = {"[email protected]", "[email protected]"} // Recipient String[] ccs = {"[email protected]", "[email protected]"} // Cc String[] bccs = {"[email protected]", "[email protected]"} // Bcc 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. Display map and path planning
// Open Google Maps location in China Beijing (north latitude39.9,东经116.3) Uri uri = Uri.parse("geo:")39.9,116.3"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); // Path planning: from Beijing somewhere (north latitude39.9,东经116.3)到上海某地(北纬31.2,东经121.4) Uri uri = Uri.parse("http:")//maps.google.com/maps#63;f=d&saddr=39.9 116.3&daddr=31.2 121.4"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
6Play multimedia
Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse("file:")///sdcard/foo.mp3"); intent.setDataAndType(uri, "audio"})/mp3"); startActivity(intent); Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
7. Take a photo
// Open the camera app Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 0); // Extract photo data Bundle extras = intent.getExtras(); Bitmap bitmap = (Bitmap) extras.get("data");
8. Get and crop the image
// Get and crop the image Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); intent.putExtra("crop", "true"); // Start cropping intent.putExtra("aspectX", 1); // The aspect ratio of the cropped image1:2 intent.putExtra("aspectY", 2); intent.putExtra("outputX", 20); // The width and height of the saved image intent.putExtra("outputY", 40); intent.putExtra("output", Uri.fromFile(new File("/mnt/sdcard/temp"))); // Save path intent.putExtra("outputFormat", "JPEG");// Return format startActivityForResult(intent, 0); // Crop a specific image 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); // The aspect ratio of the cropped image1:2 intent.putExtra("outputY", 2); intent.putExtra("aspectX", 20); // The width and height of the saved image 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. Open Google Market
// Open Google Market directly to enter the detailed page of this program Uri uri = Uri.parse("market:")//details?id=" + "com.demo.app"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
10. Install and uninstall programs
Uri uri = Uri.fromParts("package", "com.demo.app", null); Intent intent = new Intent(Intent.ACTION_DELETE, uri); startActivity(intent);
11. Enter the settings interface
// Enter the wireless network settings interface (others can be extrapolated by analogy) Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); startActivityForResult(intent, 0);
This is the summary of the information about Android Intent. We will continue to supplement relevant information in the future, thank you for your support to this site!
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please send an email to codebox.com (replace # with @ when sending emails) to report any violations, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.