與其他應用程式互動
Android 應用程式通常會提供多項活動。每項活動都會顯示使用者介面,讓使用者執行特定工作 (例如查看地圖或拍照)。為了讓使用者順利進行各種活動,應用程式必須使用 Intent
來定義應用程式的「意圖」以執行特定功能。當您利用如 startActivity()
這類方法將 Intent
傳送到系統時,系統會運用這個 Intent
來識別及啟動適當的應用程式元件。您的應用程式甚至可使用意圖,啟動另一應用程式所提供的活動。
「明確」的 Intent
可用於啟動特定元件 (即特定 Activity
例項),而「隱含」的 Intent 則用於啟動任何可處理預期動作 (例如「拍照」)的元件。
本課程會說明如何使用 Intent
與其他應用程式執行部分基本互動,例如啟動其他應用程式、接收該應用程式所提供的結果,以及讓應用程式能夠回應來自其他應用程式的意圖。
課程
- 將使用者傳送至其他應用程式
- 說明如何建立隱含意圖來啟動其他可執行特定動作的應用程式。
- 從活動取得結果
- 說明如何啟動另一活動並取得活動結果。
- 允許其他應用程式啟動您的活動
- 說明如何透過定義意圖篩選器來宣告應用程式可接受的隱含意圖,開放應用程式中的活動供其他應用程式使用。
- 管理套件瀏覽權限
- 說明如何為您的應用程式取得其他應用程式的瀏覽權限 (如果這些其他應用程式未預設可供瀏覽的話)。僅適用於指定 Android 11 (API 級別 30) 以上版本的應用程式。
- 根據用途設定套件瀏覽權限
- 說明數種應用程式互動類型,這些互動類型可能需要您更新應用程式的資訊清單檔案,才能讓您的應用程式看到其他應用程式。僅適用於指定 Android 11 (API 級別 30) 以上版本的應用程式。
如要進一步瞭解本頁所述主題,請參閱:
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2022-05-03 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"Translation issue"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]