一个app,多个入口图标,activity-alias实现多程序入口并显示指定view完成
来源:互联网 发布:路径规划软件 编辑:程序博客网 时间:2024/04/28 07:25
missed call需要一个单独的图标,点击进入,而missed call 本身在linhone activity中。
思路,使用activity alias。
当然,需要intent启动activity,也就需要filter
在android的应用程序可以有多个Activity,每个Activity是同级别的,那么在启动程序时,最先启动哪个Activity呢?有些程序可能需要显示在程序列表里,有些不需要。怎么定义呢?
android.intent.action.MAIN 决定应用程序最先启动的Activity 。
android.intent.category.LAUNCHER决定应用程序是否显示在程序列表里。
因为你的程序可能有很多个activity,
只要xml配置文件中有这么一个intent-filter,而且里面有这个launcher,那么这个activity就是点击程序时最先运行的那个activity。
隐藏icon实际上就是注释掉intent-filter中的一句
1
<
intent-filter
>
2
<
action
android:name
=
"android.intent.action.MAIN"
/>
3
<
category
android:name
=
"android.intent.category.DEFAULT"
/>
4
<!--
5
<category android:name="android.intent.category.LAUNCHER" />
6
-->
7
<
category
android:name
=
"android.intent.category.BROWSABLE"
/>
8
</
intent-filter
>
在某个Activity里用startActivity()方法发送一个intent,这个intent设定了一些条件,比如用方法setAction(),addCategory()设定了两个属性,
发送了这个intent之后,android会去系统里保存的MainManifest.xml清单(假设这个系统存放全部apk清单的文件为MainManifest.xml)里查找符合这两个属性的activity,然后启动它。
当某个Activity用startActivity(intentOther)方法向系统发送了一个intent(假如为 intentOther),那么android系统会去查找这个MainManifest.xml里注册的<intent-filter >属性,
查找到符合这个 intentOther 的就启动这个Activity,如果有多个这样的Activity符合条件的话,就跳出一个对话框让用户选择究竟要启动哪一个
以上是理论, 实际代码如下:
01
<!-- display missed call -->
02
<
activity-alias
03
android:name
=
"@string/missedcallactivity"
04
android:icon
=
"@drawable/missing_icon"
05
android:label
=
"@string/missedcallactivity"
06
android:targetActivity
=
".CustomLinphoneDialer"
>
07
<
intent-filter
>
08
<
action
android:name
=
"android.intent.action.MAIN"
/>
09
10
<
category
android:name
=
"android.intent.category.LAUNCHER"
/>
11
</
intent-filter
>
12
</
activity-alias
>
是不是 需要 多个intent filter? 下面reference a link to explan intent filter.
Intent filter
为了能支持隐式intent,activity、service和broadcast receiver会包含1到多个intent filter。每个intent filter描述组件的可接收一组intent的能力。在intent filter中,说明了可接受的类型,以及不想要的intent。隐式的intent要想投递到一个组件,只需通过组件的一个filter即可。
组件把filter分成多个,是为了针对具体不同的任务。在sample中的Note pad示例中,NoteEditor activity有两个filter,一个用于启动并打开指定的note,另一个是为了打开新的空的note。
一个intent filter是一个IntentFilter类的实例。但是,android系统必须在组件未启动的情况下就知道它的能力,因此intent filter一般不会在java代码中设置,而是在应用的manifest文件中作为<intent-filter>元素的方式声明。一个例 外是,为broadcast receiver注册动态的filter,可以调用Context.registerReceiver()方法,通过直接实例化IntentFilter 对象创建。
filter有三个平等的部分:action、data和category。隐式intent将测试这三个部分。一个intent要想投递到一个组 件,那么这三个测试都要通过才行。当然如果组件有多个intent filter,可能一个intent没有通过,但是通过了另外的一个,这样也可以把intent投递到组件。
action测试在intent filter中可以包含多个action,比如:
<intent-filter . . . >
<action android:name="com.example.project.SHOW_CURRENT" />
<action android:name="com.example.project.SHOW_RECENT" />
<action android:name="com.example.project.SHOW_PENDING" />
. . .
</intent-filter>
要想通过测试,intent中的action名称要匹配其中之一。
如果intent filter中不包含action列表,而intent指定action,那么intent没有匹配的action,不通过;intent未指定action,而intent filter指定,会自动通过测试。
category测试在intent filter中可包含category列表:
<intent-filter . . . >
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
. . .
</intent-filter>
intent想通过测试,必须匹配一个intent filter中的category。
原理上讲,intent如果没有category设置,那么总是可以通过测试。这基本上是正确的,但是有一个例外。Android在为所有隐式 intent执行startActivity()方法的时候,会认为它们至少包含了一个 android.intent.category.DEFAULT。因此,如果activity想收到隐式intent,必须加入这个category。
date测试data元素在intent filter元素中,可以重复多次(action和category不允许重复的),也可以根本没有。比如:
<intent-filter . . . >
<data android:mimeType="video/mpeg" android:scheme="http" . . . />
<data android:mimeType="audio/mpeg" android:scheme="http" . . . />
. . .
</intent-filter>
在data元素中指定uri和数据类型(MIME类型)。uri是被分开表示的:
scheme://host:port/path
其中host和port是关联的,如果host没有设置,port也会忽略。
所有这些属性都是可选的,但是不是独立的。比如,如果要设置path,那么也必须设置schema、host和port。
在比较intent中的uri和intent filter中指定的uri时,只会比较intent filter中提及的URL部分。比如,intent filter中只提及了schema,那么所有url包含这个schema的都匹配。在filter的path部分可以使用通配符做到灵活的匹配。
mimeType属性,比uri方式更常用。intent和intent filter都可以使用mime通配符的方式,比如,text/*。
如果既有mimeType,又有uri的情况,比较规则如下:
- 如果intent和intent filter都没有设置任何uri和mimetype,通过;
- intent包含uri但是没有data type的情况,intent filter的uri部分与之匹配,而且也没有data type部分,可以通过,比如mailto:和tel:
- intent对象包含数据类型但是没有uri部分,那么仅当intent filter也只有数据类型,而没有uri部分的时候能通过;
- intent对象包括uri和数据类型(或者数据类型在uri中),分两部分测试,intent对象的数据类型要匹配intent filter,intent对象的uri,或者匹配intent filter中的uri,或者intent filter中没有uri部分(仅当intent对象的uri是content:或者file:的时候)。
新思路,可以启动CustomLinphoneDialer界面,然后在跳转到呼叫记录view,
如何跳转呢?
设置全局flag,然后判断跳转,这样的话就需要在manifest中定义feature 的meta data, 保存要跳转的view, 并在CustomLinphoneDialer.java中判断。
因此新的manifest 修改为。
01
<
activity-alias
02
72 +
android:description
=
"@string/history"
03
73 +
android:icon
=
"@drawable/ic_launcher_history"
04
74 +
android:label
=
"@string/history"
05
75 +
android:name
=
"CustomHistoryActivity"
06
76 +
android:targetActivity
=
".CustomLinphoneDialer"
>
07
77 + <
intent-filter
>
08
78 + <
action
android:name
=
"android.intent.action.MAIN"
/>
09
79 +
10
80 + <
category
android:name
=
"android.intent.category.LAUNCHER"
/>
11
81 + </
intent-filter
>
12
82 +
13
83 + <
meta-data
14
84 +
android:name
=
"dltype"
15
85 +
android:value
=
"@string/dialer_history"
>
16
86 + </
meta-data
>
17
87 + </
activity-alias
>
在onCreate中判断出flag值,
01
private
void
getlauncherFlag() {
02
819
» »
// get launcher flag
03
820
» »
try
{
04
821
» » » ActivityInfo info =
this
.getPackageManager().getActivityInfo(
05
822
» » » » » getComponentName(), PackageManager.GET_META_DATA);
06
823
» » » launcherType = info.metaData.getString(
"dltype"
);
07
824
» » }
catch
(Exception e) {
08
825
» » » e.printStackTrace();
09
827
» » }
826
» » }
10
828
» }
827
» }
01
private
void
applistLoginTransferView() {
02
1537
» »
try
{
03
1538
» » » Log.d(TAG,
"launcherType="
+ launcherType);
04
1539
» » »
if
(
null
!= launcherType) {
05
1540
» » » »
if
(launcherType.equals(STRING_DIALER_CONTACT)) {
06
1541
» » » » » transfer2ContactList();
07
1542
» » » » }
else
{
08
1543
» » » » »
if
(launcherType.equals(STRING_DIALER_HISTORY)) {
09
1544
» » » » » » transfer2HistoryList();
10
1545
» » » » » }
else
{
11
1546
» » » » » »
// do nothing.
12
1547
» » » » » }
13
1548
» » » » }
14
1549
» » » }
15
1550
» » }
catch
(Exception e) {
16
1551
» » » e.printStackTrace();
17
1552
» » }
18
1521
» }
1553
» }
1
transfer2HistoryList();
到此activity-alias实现app另外程序入口并显示指定view完成
- 一个app,多个入口图标,activity-alias实现多程序入口并显示指定view完成
- 一个app,多个入口图标,activity-alias实现多程序入口并显示指定view完成
- 一个app,多个入口图标,activity-alias实现多程序入口并显示指定view完成
- 一个app,多个入口图标,activity-alias实现多程序入口并显示指定view完成
- 一个app,多个入口图标,activity-alias实现多程序入口并显示指定view完成
- activity-alias实现多程序入口并显示指定view完成
- 一个app,多个入口图标,activity-…
- 一个Activity多个入口图标的实现方法
- activity-alias 多入口配置
- Android activity-alias 多入口配置
- IOS指定APP程序入口
- Android下一个apk安装多个程序入口图标
- Android Apk安装后拥有多个程序入口图标
- Android下一个apk安装多个程序入口图标
- Android下一个apk安装多个程序入口图标
- 一个APP两个程序主入口,两个图标,互不干扰
- 一个apk多个入口,在桌面上创建多个应用图标
- 一个apk多个入口,在桌面上创建多个应用图标的桌面快捷方式
- remastersys debian or ubuntu
- 一个用VB编写的监控别人上网的软件例子
- 关于DirectUI
- Mixing Objective-C, C++ and Objective-C++: an Updated Summary
- java生成唯一ID简单方法
- 一个app,多个入口图标,activity-alias实现多程序入口并显示指定view完成
- oracle 中的OracleDBConsole(sid)无法启动
- SQL Server 表变量与临时表区别
- 支付宝接口文档。
- SWT/Jface CTabFolder隐藏或增加标签页高度问题
- Linux 线程同步---条件变量
- 多校3-1006 线段树+离散化
- Linux中Oracle10g自动备份
- POJ 2051 堆