一.Activity的啟動(dòng)方式
(1).顯示調(diào)用,要明確的指定被啟動(dòng)對(duì)象的組件信息,包括包名類名
(2).隱式調(diào)用,需要Intent能夠匹配目標(biāo)組件的IntentFilter所設(shè)置的過濾信息,過濾信息有action,category,data。為了匹配過濾列表,需要同時(shí)過濾列表中的action,category,data信息,否則失敗,一個(gè)Intent只要能匹配任何一組intent-filter即可成功啟動(dòng)Activity。

①. action的匹配規(guī)則
action是一個(gè)字符串,系統(tǒng)預(yù)定義了一些action,同時(shí)我們也可以在應(yīng)用中定義自己的action,Intent中的action必須能夠和過濾規(guī)則中的任何一個(gè)action相同,action區(qū)分大小寫。
②. category的匹配規(guī)則
category是一個(gè)字符串,系統(tǒng)預(yù)定義了一些category,同時(shí)我們也可以在應(yīng)用中定義自己的category,與action的區(qū)別是,如果Intent中含有category,那么所有的category都必須和過濾規(guī)則中的其中一個(gè)category相同。如果Intent中不含有category,其實(shí)系統(tǒng)默認(rèn)會(huì)為Intent添加上“android.intent.category.DEFAULT”。同時(shí)為了我們的activity能夠接收隱式調(diào)用,就必須在intent-filter中指定<categoryandroid:name="android.intent.category.DEFAULT"/>。
③. data的匹配規(guī)則
類似于action,如果過濾條件中定義了data,那么Intent中必須也要定義可匹配的data,
data由兩部分組成mimeType和URI.URI的結(jié)構(gòu)如下
<scheme>://<host>:<port>/[<path>|<pathPattern>|<pathPrefix>]
content://com.example.demo:80/file/image/name
http://www.baidu.com:80/search/android
data的語法如下:
<data android:scheme="string" URI模式,如http,file,content
? ? ? ? ? android:host="string" URI模式,如www.baidu.com
? ? ? ? ? android:port="string" URI模式,端口號(hào)
? ? ? ? ? android:path="string" URI模式 路徑信息
? ? ? ? ? android:pathPattern="string"
? ? ? ? ? android:pathPrefix="string"
? ? ? ? ? android:mimeType="string"/>?
具體使用:
Intent intent = new Intent("android.intent.action.SEND.MULTIPLE");
intent.addCategory("android.intent.category.DEFAULT");
intent.setDataAndType(Uri.parse("content://com.example.demo:80/file"),"image/*");
startActivity(intent);
舉例打開QQ
String url="mqqwpa://im/chat?chat_type=wpa&uin=771346371";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
舉例打開簡(jiǎn)書
String url = "intent://notes/56ea25fbe5cf/#Intent;scheme=jianshu;package=com.jianshu.haruki;end"
startActivity(Intent.parseUri(url,0));