首页 > 其他 > 详细

intent(2、隐形intent)

时间:2015-01-23 21:27:34      阅读:201      评论:0      收藏:0      [点我收藏+]

1、intent可以通过intent-filter隐形调用,常用方法如下:

private final static String MY_ACTION = "com.example.ACTION.other";

Intent intent1 = new Intent();
intent1.setAction(MY_ACTION);
startActivity(intent1);

同时配置manifest.xml:

        <activity android:name="com.example.demo04.OtherActivity">
            <intent-filter>
                <action android:name="com.example.ACTION.other" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

2、intent-filter里有几个参数要注意,它对应着intent的几个属性,包括

  • Action:Action属性的值为一个字符串,它代表了系统中已经定义了一系列常用的动作。通过setAction()方法或在清单文件AndroidManifest.xml中设置。默认为:DEFAULT。
  • Data:Data通常是URI格式定义的操作数据。例如:tel:// 。通过setData()方法设置。
  • Category:Category属性用于指定当前动作(Action)被执行的环境。通过addCategory()方法或在清单文件AndroidManifest.xml中设置。默认为:CATEGORY_DEFAULT。
  • Extras:Extras属性主要用于传递目标组件所需要的额外的数据。通过putExtras()方法设置。

3、Category的例子:

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <!--  category android:name="android.intent.category.LAUNCHER"/-->
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" /> 
            </intent-filter>

此时,点击home键,该activity会提示用户是否选择,常用在桌面应用上。

4、几个系统intent的例子:

//浏览网页
Uri uri = Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
                    
//拨打电话
Uri uri = Uri.parse("tel:12321312312");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
                                    
//查看图片
Intent i = new Intent();
i.setType("image/*");                    
i.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(i,
11);

 

intent(2、隐形intent)

原文:http://www.cnblogs.com/Fredric-2013/p/4214916.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!