โต้ตอบกับแอปอื่นๆ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
แอป Android มักจะมีกิจกรรมหลายรายการ กิจกรรมแต่ละรายการจะแสดงอินเทอร์เฟซผู้ใช้ที่ช่วยให้ผู้ใช้ทำงานบางอย่างได้ เช่น ดูแผนที่หรือถ่ายภาพ
หากต้องการนำผู้ใช้จากกิจกรรมหนึ่งไปยังอีกกิจกรรมหนึ่ง แอปของคุณต้องใช้ Intent
เพื่อกำหนด "ความตั้งใจ" ของแอปในการดำเนินการ เมื่อคุณส่ง Intent
ไปยังระบบด้วยเมธอด เช่น startActivity()
ระบบจะใช้ Intent
เพื่อระบุและเริ่มคอมโพเนนต์แอปที่เหมาะสม การใช้ Intent ยังช่วยให้แอปเริ่มกิจกรรมที่อยู่ในแอปอื่นได้อีกด้วย
Intent
อาจเป็นแบบเจาะจงเพื่อเริ่มActivity
อินสแตนซ์ที่เฉพาะเจาะจง หรือแบบไม่เจาะจงเพื่อเริ่มคอมโพเนนต์ใดก็ได้ที่จัดการการดำเนินการที่ต้องการได้ เช่น "จับภาพ"
หัวข้อในคู่มือนี้จะแสดงวิธีใช้ Intent
เพื่อดำเนินการพื้นฐานบางอย่างกับแอปอื่นๆ เช่น การเริ่มแอปอื่น การรับผลลัพธ์จากแอปนั้น และทำให้แอปของคุณตอบสนองต่อ Intent จากแอปอื่นๆ ได้
หัวข้อ
- การส่งผู้ใช้ไปยังแอปอื่น
- แสดงวิธีสร้าง Intent ที่ไม่ชัดแจ้งเพื่อเปิดแอปอื่นๆ ที่ดําเนินการได้
- รับผลลัพธ์จากกิจกรรม
- แสดงวิธีเริ่มกิจกรรมอื่นและรับผลลัพธ์จากกิจกรรม
- อนุญาตให้แอปอื่นๆ เริ่มกิจกรรมของคุณ
- แสดงวิธีทำให้กิจกรรมในแอปเปิดอยู่เพื่อให้แอปอื่นๆ ใช้ได้โดยกำหนดตัวกรอง Intent ที่ประกาศ Intent ที่ไม่ชัดแจ้งที่แอปยอมรับ
- การกรองระดับการมองเห็นแพ็กเกจใน Android
- แสดงวิธีทำให้แอปอื่นๆ มองเห็นแอปของคุณได้หากแอปเหล่านั้นไม่แสดงโดยค่าเริ่มต้น มีผลเฉพาะกับแอปที่กำหนดเป้าหมายเป็น Android 11 (API ระดับ 30) ขึ้นไป
- ตอบสนอง Use Case ทั่วไปขณะที่มองเห็นแพ็กเกจได้แบบจํากัด
- แสดงการโต้ตอบของแอปหลายประเภทที่อาจกำหนดให้คุณอัปเดตไฟล์ Manifest ของแอปเพื่อให้แอปอื่นๆ มองเห็นแอปของคุณได้
มีผลกับแอปที่กำหนดเป้าหมายเป็น Android 11 (API ระดับ 30) ขึ้นไปเท่านั้น
- จำกัดการโหลดในคอนเทนเนอร์ Android ในอุปกรณ์
- แสดงวิธีจำกัดไม่ให้แอป Play Store โหลดในแอปสภาพแวดล้อม Android ที่จำลอง ซึ่งก็คือคอนเทนเนอร์ Android ในอุปกรณ์
ดูข้อมูลเพิ่มเติมเกี่ยวกับหัวข้อในหน้านี้ได้ที่หัวข้อต่อไปนี้
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-02-10 UTC
[null,null,["อัปเดตล่าสุด 2025-02-10 UTC"],[],[],null,["# Interact with other apps\n\nAn Android app typically has several [activities](/guide/components/activities). Each activity displays a\nuser interface that lets the user perform a specific task, such as viewing a map or taking a photo.\nTo take the user from one activity to another, your app must use an [Intent](/reference/android/content/Intent) to define your app's \"intent\" to do something. When you pass an\n`Intent` to the system with a method\nsuch as [startActivity()](/reference/android/app/Activity#startActivity(android.content.Intent)),\nthe system uses the `Intent` to identify and start the appropriate app component. Using intents\neven lets your app start an activity that is contained in a separate app.\n\nAn `Intent` can be *explicit* , to start\na specific [Activity](/reference/android/app/Activity) instance,\nor *implicit*, to start any\ncomponent that can handle the intended action, such as \"capture a photo.\"\n\nThe topics in this guide show you how to use an `Intent` to perform some basic\ninteractions with other apps, such as starting another app, receiving a result from that app, and\nmaking your app able to respond to intents from other apps.\n\nTopics\n------\n\n**[Sending the user to another app](/training/basics/intents/sending)**\n: Shows you how to create implicit intents to launch other apps that can perform an\n action.\n\n**[Get a result from an activity](/training/basics/intents/result)**\n: Shows you how to start another activity and receive a result from the activity.\n\n**[Allow other apps to start your activity](/training/basics/intents/filters)**\n: Shows you how to make activities in your app open for use by other apps by defining\n intent filters that declare the implicit intents your app accepts.\n\n**[Package visibility filtering on Android](/training/basics/intents/package-visibility)**\n: Shows you how to make other apps visible to your app if they\n aren't visible by default. Applies only to apps that target Android 11\n (API level 30) or higher.\n\n**[Fulfill common use cases while\nhaving limited package visibility](/training/basics/intents/package-visibility-use-cases)**\n: Shows several types of app interactions that might require you to update\n your app's manifest file so that other apps are visible to your app.\n Applies only to apps that target Android 11 (API level 30) or higher.\n\n**[Limit loading in on-device Android containers](/training/basics/intents/limit-play-loading)**\n: Shows you how to limit your Play Store app from loading in a simulated\n Android environment app, also known as an on-device Android container.\n\nFor additional information about the topics on this page, see the following:\n\n- [Sharing simple data](/training/sharing)\n- [Sharing files](/training/secure-file-sharing)\n- [Integrating Application with Intents](http://android-developers.blogspot.com/2009/11/integrating-application-with-intents.html) blog post\n- [Intents and Intent\n Filters](/guide/components/intents-filters)"]]