Android Intent 用法全面总结(转载)

1. [代码]调用拨号程序


1

2

3

4

// 给移动客服10086拨打电话

Uri uri = Uri.parse("tel:10086");

Intent intent = new Intent(Intent.ACTION_DIAL, uri);

startActivity(intent);

2. [代码]发送短信或彩信


1

2

3

4

5

6

7

8

9

10

11

12

// 给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. [代码]通过浏览器打开网页


1

2

3

4

// 打开Google主页

Uri uri = Uri.parse("http://www.google.com");

Intent intent  = new Intent(Intent.ACTION_VIEW, uri);

startActivity(intent);

4. [代码]发送电子邮件


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

// 给[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. [代码]显示地图与路径规划


1

2

3

4

5

6

7

8

// 打开Google地图中国北京位置(北纬39.9,东经116.3)

Uri uri = Uri.parse("geo:39.9,116.3");

Intent intent = new Intent(Intent.ACTION_VIEW, uri);

startActivity(intent);

// 路径规划:从北京某地(北纬39.9,东经116.3)到上海某地(北纬31.2,东经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. [代码]播放多媒体


1

2

3

4

5

6

7

8

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. [代码]拍照


1

2

3

4

5

6

// 打开拍照程序

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(intent, 0);

// 取出照片数据

Bundle extras = intent.getExtras();

Bitmap bitmap = (Bitmap) extras.get("data");

8. [代码]获取并剪切图片


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

// 获取并剪切图片

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType("image/*");

intent.putExtra("crop", "true"); // 开启剪切

intent.putExtra("aspectX", 1); // 剪切的宽高比为1:2

intent.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:2

intent.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. [代码]打开Google Market


1

2

3

4

// 打开Google Market直接进入该程序的详细页面

Uri uri = Uri.parse("market://details?id=" + "com.demo.app");

Intent intent = new Intent(Intent.ACTION_VIEW, uri);

startActivity(intent);

10. [代码]安装和卸载程序


1

2

3

Uri uri = Uri.fromParts("package", "com.demo.app", null); 

Intent intent = new Intent(Intent.ACTION_DELETE, uri); 

startActivity(intent);

11. [代码]进入设置界面


1

2

3

// 进入无线网络设置界面(其它可以举一反三) 

Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); 

startActivityForResult(intent, 0);

时间: 2024-07-30 04:31:54

Android Intent 用法全面总结(转载)的相关文章

Android Intent用法总结

Android中提供了Intent机制来协助应用间的交互与通讯,Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组件,将 Intent传递给调用的组件,并完成组件的调用.Intent不仅可用于应用程序之间,也可用于应用程序内部的 Activity / Service之间的交互.因此,Intent在这里起着一个媒体中介的作用,专门提供组件互相调用的相关信息,实现调用者与被调用者之间的解耦. 1. Intent作用 In

Android Intent 用法全面总结

[代码] 调用拨号程序   // 给移动客服10086拨打电话    Uri uri = Uri.parse("tel:10086");    Intent intent = new Intent(Intent.ACTION_DIAL, uri);    startActivity(intent); [代码] 发送短信或彩信    // 给10086发送内容为“Hello”的短信    Uri uri = Uri.parse("smsto:10086");    I

android Bitmap用法总结(转载)

Bitmap用法总结1.Drawable → Bitmappublic static Bitmap drawableToBitmap(Drawable drawable) {Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_888

Android基础知识:Day06 Activity生命周期和Intent用法

Day06 Activity生命周期和Intent用法 一.Activity的跳转 1. 创建第二个Activity 需要在清单文件中为其配置一个activity标签 标签中如果带有这个子节点,则会在系统中多创建一个快捷图标 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.cate

android intent隐式调用之一个应用程序启动另一个应用程序(转载)

理解Intent的关键之一是理解清楚Intent的两种基本用法:一种是显式的Intent,即在构造Intent对象时就指定接收者,这种方式与普通的函数调用类似:另一种是隐式的Intent,即Intent的发送者在构造Intent对象时,并不知道也不关心接收者是谁,这种方式与函数调用差别比较大,有利于降低发送者和接收者之间的耦合.另外Intent除了发送外,还可用于广播. 显示调用 1.Intent intent = new Intent(); intent.setClass(A.this,B.c

android intent和intent action大全

1.Intent的用法: (1)用Action跳转 1.使用Action跳转,如果有一个程序的AndroidManifest.xml中的某一个 Activity的IntentFilter段中 定义了包含了相同的Action那么这个Intent就与这个目标Action匹配.如果这个IntentFilter段中没有定义 Type,Category,那么这个 Activity就匹配了.但是如果手机中有两个以上的程序匹配,那么就会弹出一个对话可框来提示说明. Action 的值在Android中有很多预

Android学习之路(转载)

原文地址:http://stormzhang.github.io/android/2014/07/07/learn-android-from-rookie/ 硬件 电脑–推荐Mac 首先声明我不是果粉,个人Windows,Linux,Mac OX系统均用过, 只能说Windows上面的开发工具简直难以恭维,尤其命令行超级难用,而Linux自己必须得花不少时间在折腾中,更是不适合新手了,Max OS是我认为迄今为止最好用的系统,没有之一, 所以如果你不差钱的话,强烈建议入手一台Mac,推荐Pro系

android之android.intent.category.DEFAULT的用途和使用

转载(http://blog.csdn.net/jason0539/article/details/10049899) 1.要弄清楚这个问题,首先需要弄明白什么是implicit(隐藏) intent什么是explicit(明确) intent. Explicit Intent明确的指定了要启动的Acitivity ,比如以下Java代码: Intent intent= new Intent(this, B.class): Implicit Intent没有明确的指定要启动哪个Activity

Intent用法简介

Intent作为联系各Activity之间的纽带,其作用并不仅仅只限于简单的数据传递.通过其自带的属性,其实可以方便的完成很多较为复杂的操作.例如直接调用拨号功能.直接自动调用合适的程序打开不同类型的文件等等.诸如此类,都可以通过设置Intent属性来完成. Intent主要有以下四个重要属性,它们分别为:            Action:Action属性的值为一个字符串,它代表了系统中已经定义了一系列常用的动作.通过setAction()方法或在清单文件AndroidManifest.xm