To help developers be more intentional with defining user-facing foreground
services, Android 10 introduced the android:foregroundServiceType
attribute within the <service> element.
If your app targets Android 14, it must specify appropriate foreground service types. As in previous versions of Android, multiple types can be combined. This list shows the foreground service types to choose from:
cameraconnectedDevicedataSynchealthlocationmediaPlaybackmediaProjectionmicrophonephoneCallremoteMessagingshortServicespecialUsesystemExempted
If a use case in your app isn't associated with any of these types, we strongly recommend that you migrate your logic to use WorkManager or user-initiated data transfer jobs.
The health, remoteMessaging, shortService, specialUse, and systemExempted
types are new in Android 14.
The following code snippet provides an example of a foreground service type declaration in the manifest:
<manifest ...>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<application ...>
<service
android:name=".MyMediaPlaybackService"
android:foregroundServiceType="mediaPlayback"
android:exported="false">
</service>
</application>
</manifest>
If an app that targets Android 14 doesn't define types for a given service in
the manifest, then the system will raise MissingForegroundServiceTypeException
upon calling startForeground() for that service.
ফোরগ্রাউন্ড পরিষেবার প্রকারগুলি ব্যবহার করার জন্য নতুন অনুমতি ঘোষণা করুন৷
যদি Android 14 কে লক্ষ্য করে এমন অ্যাপগুলি একটি ফোরগ্রাউন্ড পরিষেবা ব্যবহার করে, তাহলে তাদের অবশ্যই একটি নির্দিষ্ট অনুমতি ঘোষণা করতে হবে, ফোরগ্রাউন্ড পরিষেবার প্রকারের উপর ভিত্তি করে, যা Android 14 প্রবর্তন করে। এই অনুমতিগুলি এই পৃষ্ঠার প্রতিটি ফোরগ্রাউন্ড পরিষেবা টাইপ বিভাগের জন্য উদ্দিষ্ট ব্যবহারের ক্ষেত্রে এবং প্রয়োগের ক্ষেত্রে "অনুমতি যা আপনাকে অবশ্যই আপনার ম্যানিফেস্ট ফাইলে ঘোষণা করতে হবে" লেবেলযুক্ত বিভাগগুলিতে উপস্থিত হয়৷
সমস্ত অনুমতি সাধারণ অনুমতি হিসাবে সংজ্ঞায়িত করা হয় এবং ডিফল্টরূপে দেওয়া হয়। ব্যবহারকারীরা এই অনুমতি প্রত্যাহার করতে পারবেন না।
রানটাইমে অগ্রভাগের পরিষেবার ধরন অন্তর্ভুক্ত করুন
The best practice for applications starting foreground services is to use the
ServiceCompat version of startForeground() (available in androidx-core
1.12 and higher) where you pass in a bitwise
integer of foreground service types. You can choose to pass one or more type
values.
Usually, you should declare only the types required for a particular use case. This makes it easier to meet the system's expectations for each foreground service type. In cases where a foreground service is started with multiple types, then the foreground service must adhere to the platform enforcement requirements of all types.
ServiceCompat.startForeground(0, notification, FOREGROUND_SERVICE_TYPE_LOCATION)
If the foreground service type is not specified in the call, the type defaults
to the values defined in the manifest. If you didn't specify the service
type in the manifest, the system throws
MissingForegroundServiceTypeException.
If the foreground service needs new permissions after you launch it, you
should call startForeground() again and add the new service types. For
example, suppose a fitness app runs a running-tracker service that always needs
location information, but might or might not need media permissions. You
would need to declare both location and mediaPlayback in the manifest. If a
user starts a run and just wants their location tracked, your app should call
startForeground() and pass just the location service type. Then, if the user
wants to start playing audio, call startForeground() again and pass
location|mediaPlayback.
সিস্টেম রানটাইম চেক
সিস্টেমটি ফোরগ্রাউন্ড পরিষেবার ধরনগুলির সঠিক ব্যবহারের জন্য পরীক্ষা করে এবং নিশ্চিত করে যে অ্যাপটি সঠিক রানটাইম অনুমতির জন্য অনুরোধ করেছে বা প্রয়োজনীয় API ব্যবহার করেছে৷ উদাহরণস্বরূপ, সিস্টেম আশা করে যে অ্যাপগুলি ফোরগ্রাউন্ড পরিষেবার প্রকার FOREGROUND_SERVICE_TYPE_LOCATION ব্যবহার করে ACCESS_COARSE_LOCATION বা ACCESS_FINE_LOCATION এর জন্য অনুরোধ করবে৷
এটি বোঝায় যে ব্যবহারকারীর কাছ থেকে অনুমতির অনুরোধ করার সময় এবং ফোরগ্রাউন্ড পরিষেবাগুলি শুরু করার সময় অ্যাপগুলিকে অবশ্যই একটি নির্দিষ্ট ক্রিয়াকলাপ অনুসরণ করতে হবে৷ অ্যাপটি startForeground() কে কল করার চেষ্টা করার আগে অনুমতির অনুরোধ করতে হবে এবং মঞ্জুর করতে হবে। যে অ্যাপগুলি ফোরগ্রাউন্ড পরিষেবা শুরু হওয়ার পরে উপযুক্ত অনুমতিগুলির জন্য অনুরোধ করে তাদের অবশ্যই এই ক্রিয়াকলাপের ক্রম পরিবর্তন করতে হবে এবং ফোরগ্রাউন্ড পরিষেবা শুরু করার আগে অনুমতির অনুরোধ করতে হবে৷
প্ল্যাটফর্ম প্রয়োগের সুনির্দিষ্ট বৈশিষ্ট্যগুলি এই পৃষ্ঠার প্রতিটি ফোরগ্রাউন্ড পরিষেবা প্রকার বিভাগের জন্য উদ্দেশ্যমূলক ব্যবহারের ক্ষেত্রে এবং প্রয়োগের ক্ষেত্রে "রানটাইম প্রয়োজনীয়তা" লেবেলযুক্ত বিভাগগুলিতে প্রদর্শিত হয়।
প্রতিটি ফোরগ্রাউন্ড পরিষেবার প্রকারের জন্য উদ্দেশ্যযুক্ত ব্যবহারের ক্ষেত্রে এবং প্রয়োগ
为了使用给定的前台服务类型,您必须在清单文件中声明特定权限,必须满足特定的运行时要求,并且应用必须满足该类型的其中一组预期用例。以下部分介绍了您必须声明的权限、运行时前提条件以及每种类型的预期用例。
ক্যামেরা
- 要在
android:foregroundServiceType下在清单中声明的前台服务类型 camera- 在清单中声明的权限
FOREGROUND_SERVICE_CAMERA- 要传递给
startForeground()的常量 FOREGROUND_SERVICE_TYPE_CAMERA- 运行时前提条件
请求并获得
CAMERA运行时权限注意:
CAMERA运行时权限受使用时限制的约束。因此,除少数例外情况外,您无法在应用在后台运行时创建camera前台服务。如需了解详情,请参阅与启动需要“使用时”权限的前台服务相关的限制。- 说明
继续在后台访问相机,例如支持多任务的视频聊天应用。
সংযুক্ত ডিভাইস
- ফোরগ্রাউন্ড সার্ভিস টাইপ যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
-
android:foregroundServiceType -
connectedDevice - আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
-
FOREGROUND_SERVICE_CONNECTED_DEVICE -
startForeground()এ পাস করার জন্য ধ্রুবক -
FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE - রানটাইম পূর্বশর্ত
নিম্নলিখিত শর্তগুলির মধ্যে অন্তত একটি সত্য হতে হবে:
আপনার ম্যানিফেস্টে নিম্নলিখিত অনুমতিগুলির মধ্যে অন্তত একটি ঘোষণা করুন:
অনুরোধ করুন এবং নিম্নলিখিত রানটাইম অনুমতিগুলির মধ্যে অন্তত একটি মঞ্জুর করুন:
- বর্ণনা
ব্লুটুথ, এনএফসি, আইআর, ইউএসবি বা নেটওয়ার্ক সংযোগের প্রয়োজন বাহ্যিক ডিভাইসগুলির সাথে মিথস্ক্রিয়া।
- বিকল্প
যদি আপনার অ্যাপটিকে একটি বাহ্যিক ডিভাইসে ক্রমাগত ডেটা স্থানান্তর করতে হয়, তবে পরিবর্তে সহচর ডিভাইস ম্যানেজার ব্যবহার করার কথা বিবেচনা করুন। সহচর ডিভাইসের পরিসরে থাকাকালীন আপনার অ্যাপটি চলমান থাকতে সাহায্য করার জন্য সহচর ডিভাইস উপস্থিতি API ব্যবহার করুন৷
আপনার অ্যাপটিকে ব্লুটুথ ডিভাইসের জন্য স্ক্যান করার প্রয়োজন হলে, পরিবর্তে ব্লুটুথ স্ক্যান API ব্যবহার করার কথা বিবেচনা করুন।
ডেটা সিঙ্ক
- 要在清单中的以下位置声明的前台服务类型
android:foregroundServiceTypedataSync- 在清单中声明的权限
FOREGROUND_SERVICE_DATA_SYNC- 要传递给
startForeground()的常量 FOREGROUND_SERVICE_TYPE_DATA_SYNC- 运行时前提条件
- 无
- 说明
数据传输操作,例如:
- 数据上传或下载
- 备份和恢复操作
- 导入或导出操作
- 获取数据
- 本地文件处理
- 通过网络在设备和云端之间传输数据
- 替代方案
如需了解详情,请参阅数据同步前台服务的替代方案。
স্বাস্থ্য
- Foreground service type to declare in manifest under
android:foregroundServiceTypehealth- Permission to declare in your manifest
FOREGROUND_SERVICE_HEALTH- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_HEALTH- Runtime prerequisites
At least one of the following conditions must be true:
Declare the
HIGH_SAMPLING_RATE_SENSORSpermission in your manifest.Request and be granted at least one of the following runtime permissions:
BODY_SENSORSon API level 35 and lowerREAD_HEART_RATEREAD_SKIN_TEMPERATUREREAD_OXYGEN_SATURATIONACTIVITY_RECOGNITION
Note: The
BODY_SENSORSand sensor-based READ runtime permissions are subject to while-in-use restrictions. For this reason, you cannot create ahealthforeground service that uses body sensors while your app is in the background unless you've been granted theBODY_SENSORS_BACKGROUND(API level 33 to 35) orREAD_HEALTH_DATA_IN_BACKGROUND(API level 36 and higher) permissions. For more information, see Restrictions on starting foreground services that need while-in-use permissions.- Description
Any long-running use cases to support apps in the fitness category such as exercise trackers.
অবস্থান
- 要在清单中的以下位置声明的前台服务类型
android:foregroundServiceTypelocation- 在清单中声明的权限
FOREGROUND_SERVICE_LOCATION- 要传递给
startForeground()的常量 FOREGROUND_SERVICE_TYPE_LOCATION- 运行时前提条件
用户必须已启用位置信息服务,并且应用必须至少获得以下一项运行时权限:
注意:如需检查用户是否已启用位置信息服务以及是否已授予对运行时权限的访问权限,请使用
PermissionChecker#checkSelfPermission()注意:位置信息运行时权限受“使用期间”限制。因此,除非您已获得
ACCESS_BACKGROUND_LOCATION运行时权限,否则无法在应用在后台运行时创建location前台服务。如需了解详情,请参阅与启动需要“使用时”权限的前台服务相关的限制。- 说明
需要位置信息使用权的长时间运行的用例,例如导航和位置信息分享。
- 替代方案
如果您的应用需要在用户到达特定位置时触发,请考虑改用 Geofence API。
মিডিয়া
- 要在清单中的以下位置声明的前台服务类型
android:foregroundServiceTypemediaPlayback- 在清单中声明的权限
FOREGROUND_SERVICE_MEDIA_PLAYBACK- 要传递给
startForeground()的常量 FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK- 运行时前提条件
- 无
- 说明
- 在后台继续播放音频或视频。在 Android TV 上支持数字视频录制 (DVR) 功能。
- 替代方案
- 如果您要显示画中画视频,请使用画中画模式。
মিডিয়া অভিক্ষেপ
- ফোরগ্রাউন্ড পরিষেবার ধরন যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
-
android:foregroundServiceType -
mediaProjection - আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
-
FOREGROUND_SERVICE_MEDIA_PROJECTION -
startForeground()এ পাস করার জন্য ধ্রুবক -
FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION - রানটাইম পূর্বশর্ত
ফোরগ্রাউন্ড পরিষেবা শুরু করার আগে
createScreenCaptureIntent()পদ্ধতিতে কল করুন। এটি করা ব্যবহারকারীকে একটি অনুমতি বিজ্ঞপ্তি দেখায়; আপনি পরিষেবা তৈরি করার আগে ব্যবহারকারীকে অবশ্যই অনুমতি দিতে হবে।আপনি ফোরগ্রাউন্ড পরিষেবা তৈরি করার পরে, আপনি
MediaProjectionManager.getMediaProjection()কল করতে পারেন।- বর্ণনা
MediaProjectionAPIs ব্যবহার করে নন-প্রাথমিক ডিসপ্লে বা বাহ্যিক ডিভাইসে প্রজেক্ট কন্টেন্ট। এই বিষয়বস্তু একচেটিয়াভাবে মিডিয়া বিষয়বস্তু হতে হবে না.- বিকল্প
অন্য ডিভাইসে মিডিয়া স্ট্রিম করতে, Google Cast SDK ব্যবহার করুন৷
- ফোরগ্রাউন্ড পরিষেবার ধরন যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
-
android:foregroundServiceType -
mediaProjection - আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
-
FOREGROUND_SERVICE_MEDIA_PROJECTION -
startForeground()এ পাস করার জন্য ধ্রুবক -
FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION - রানটাইম পূর্বশর্ত
ফোরগ্রাউন্ড পরিষেবা শুরু করার আগে
createScreenCaptureIntent()পদ্ধতিতে কল করুন। এটি করা ব্যবহারকারীকে একটি অনুমতি বিজ্ঞপ্তি দেখায়; আপনি পরিষেবা তৈরি করার আগে ব্যবহারকারীকে অবশ্যই অনুমতি দিতে হবে।আপনি ফোরগ্রাউন্ড পরিষেবা তৈরি করার পরে, আপনি
MediaProjectionManager.getMediaProjection()কল করতে পারেন।- বর্ণনা
MediaProjectionAPIs ব্যবহার করে নন-প্রাথমিক ডিসপ্লে বা বাহ্যিক ডিভাইসে প্রজেক্ট কন্টেন্ট। এই বিষয়বস্তু একচেটিয়াভাবে মিডিয়া বিষয়বস্তু হতে হবে না.- বিকল্প
অন্য ডিভাইসে মিডিয়া স্ট্রিম করতে, Google Cast SDK ব্যবহার করুন৷
- ফোরগ্রাউন্ড পরিষেবার ধরন যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
-
android:foregroundServiceType -
mediaProjection - আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
-
FOREGROUND_SERVICE_MEDIA_PROJECTION -
startForeground()এ পাস করার জন্য ধ্রুবক -
FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION - রানটাইম পূর্বশর্ত
ফোরগ্রাউন্ড পরিষেবা শুরু করার আগে
createScreenCaptureIntent()পদ্ধতিতে কল করুন। এটি করা ব্যবহারকারীকে একটি অনুমতি বিজ্ঞপ্তি দেখায়; আপনি পরিষেবা তৈরি করার আগে ব্যবহারকারীকে অবশ্যই অনুমতি দিতে হবে।আপনি ফোরগ্রাউন্ড পরিষেবা তৈরি করার পরে, আপনি
MediaProjectionManager.getMediaProjection()কল করতে পারেন।- বর্ণনা
MediaProjectionAPIs ব্যবহার করে নন-প্রাথমিক ডিসপ্লে বা বাহ্যিক ডিভাইসে প্রজেক্ট কন্টেন্ট। এই বিষয়বস্তু একচেটিয়াভাবে মিডিয়া বিষয়বস্তু হতে হবে না.- বিকল্প
অন্য ডিভাইসে মিডিয়া স্ট্রিম করতে, Google Cast SDK ব্যবহার করুন৷
- ফোরগ্রাউন্ড পরিষেবার ধরন যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
-
android:foregroundServiceType -
mediaProjection - আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
-
FOREGROUND_SERVICE_MEDIA_PROJECTION -
startForeground()এ পাস করার জন্য ধ্রুবক -
FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION - রানটাইম পূর্বশর্ত
ফোরগ্রাউন্ড পরিষেবা শুরু করার আগে
createScreenCaptureIntent()পদ্ধতিতে কল করুন। এটি করা ব্যবহারকারীকে একটি অনুমতি বিজ্ঞপ্তি দেখায়; আপনি পরিষেবা তৈরি করার আগে ব্যবহারকারীকে অবশ্যই অনুমতি দিতে হবে।আপনি ফোরগ্রাউন্ড পরিষেবা তৈরি করার পরে, আপনি
MediaProjectionManager.getMediaProjection()কল করতে পারেন।- বর্ণনা
MediaProjectionAPIs ব্যবহার করে নন-প্রাথমিক ডিসপ্লে বা বাহ্যিক ডিভাইসে প্রজেক্ট কন্টেন্ট। এই বিষয়বস্তু একচেটিয়াভাবে মিডিয়া বিষয়বস্তু হতে হবে না.- বিকল্প
অন্য ডিভাইসে মিডিয়া স্ট্রিম করতে, Google Cast SDK ব্যবহার করুন৷
মাইক্রোফোন
- ফোরগ্রাউন্ড সার্ভিস টাইপ যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
-
android:foregroundServiceType -
microphone - আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
-
FOREGROUND_SERVICE_MICROPHONE -
startForeground()এ পাস করার জন্য ধ্রুবক -
FOREGROUND_SERVICE_TYPE_MICROPHONE - রানটাইম পূর্বশর্ত
অনুরোধ করুন এবং
RECORD_AUDIOরানটাইম অনুমতি মঞ্জুর করুন৷দ্রষ্টব্য:
RECORD_AUDIOরানটাইম অনুমতি ব্যবহারের সময় বিধিনিষেধ সাপেক্ষে। এই কারণে, কিছু ব্যতিক্রম ছাড়া আপনার অ্যাপটি ব্যাকগ্রাউন্ডে থাকাকালীন আপনি একটিmicrophoneফোরগ্রাউন্ড পরিষেবা তৈরি করতে পারবেন না৷ আরও তথ্যের জন্য, ফোরগ্রাউন্ড পরিষেবাগুলি শুরু করার বিধিনিষেধগুলি দেখুন যার ব্যবহারের সময় অনুমতি প্রয়োজন ৷- বর্ণনা
পটভূমি থেকে মাইক্রোফোন ক্যাপচার চালিয়ে যান, যেমন ভয়েস রেকর্ডার বা যোগাযোগ অ্যাপ।
ফোন কল
- ফোরগ্রাউন্ড সার্ভিস টাইপ যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
-
android:foregroundServiceType -
phoneCall - আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
-
FOREGROUND_SERVICE_PHONE_CALL -
startForeground()এ পাস করার জন্য ধ্রুবক -
FOREGROUND_SERVICE_TYPE_PHONE_CALL - রানটাইম পূর্বশর্ত
এই শর্তগুলির মধ্যে অন্তত একটি সত্য হতে হবে:
- অ্যাপ তার ম্যানিফেস্ট ফাইলে
MANAGE_OWN_CALLSঅনুমতি ঘোষণা করেছে।
- অ্যাপ তার ম্যানিফেস্ট ফাইলে
- অ্যাপ হল
ROLE_DIALERভূমিকার মাধ্যমে ডিফল্ট ডায়ালার অ্যাপ।
- অ্যাপ হল
- বর্ণনা
ConnectionServiceAPI ব্যবহার করে একটি চলমান কল চালিয়ে যান।- বিকল্প
আপনার যদি ফোন, ভিডিও বা ভিওআইপি কল করার প্রয়োজন হয়, তাহলে
android.telecomলাইব্রেরি ব্যবহার করার কথা বিবেচনা করুন।কল স্ক্রিন করতে
CallScreeningServiceব্যবহার করার কথা বিবেচনা করুন।
রিমোট মেসেজিং
- Foreground service type to declare in manifest under
android:foregroundServiceTyperemoteMessaging- Permission to declare in your manifest
FOREGROUND_SERVICE_REMOTE_MESSAGING- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING- Runtime prerequisites
- None
- Description
- Transfer text messages from one device to another. Assists with continuity of a user's messaging tasks when they switch devices.
সংক্ষিপ্ত পরিষেবা
- Foreground service type to declare in manifest under
android:foregroundServiceTypeshortService- Permission to declare in your manifest
- None
- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_SHORT_SERVICE- Runtime prerequisites
- None
- Description
Quickly finish critical work that cannot be interrupted or postponed.
This type has some unique characteristics:
- Can only run for a short period of time (about 3 minutes).
- No support for sticky foreground services.
- Cannot start other foreground services.
- Doesn't require a type-specific permission, though it still
requires the
FOREGROUND_SERVICEpermission. - A
shortServicecan only change to another service type if the app is currently eligible to start a new foreground service. - A foreground service can change its type to
shortServiceat any time, at which point the timeout period begins.
The timeout for shortService begins from the moment that
Service.startForeground()is called. The app is expected to callService.stopSelf()orService.stopForeground()before the timeout occurs. Otherwise, the newService.onTimeout()is called, giving apps a brief opportunity to callstopSelf()orstopForeground()to stop their service.A short time after
Service.onTimeout()is called, the app enters a cached state and is no longer considered to be in the foreground, unless the user is actively interacting with the app. A short time after the app is cached and the service has not stopped, the app receives an ANR. The ANR message mentionsFOREGROUND_SERVICE_TYPE_SHORT_SERVICE. For these reasons, it's considered best practice to implement theService.onTimeout()callback.The
Service.onTimeout()callback doesn't exist on Android 13 and lower. If the same service runs on such devices, it doesn't receive a timeout, nor does it ANR. Make sure that your service stops as soon as it finishes the processing task, even if it hasn't received theService.onTimeout()callback yet.It's important to note that if the timeout of the
shortServiceis not respected, the app will ANR even if it has other valid foreground services or other app lifecycle processes running.If an app is visible to the user or satisfies one of the exemptions that allow foreground services to be started from the background, calling
Service.StartForeground()again with theFOREGROUND_SERVICE_TYPE_SHORT_SERVICEparameter extends the timeout by another 3 minutes. If the app isn't visible to the user and doesn't satisfy one of the exemptions, any attempt to start another foreground service, regardless of type, causes aForegroundServiceStartNotAllowedException.If a user disables battery optimization for your app, it's still affected by the timeout of shortService FGS.
If you start a foreground service that includes the
shortServicetype and another foreground service type, the system ignores theshortServicetype declaration. However, the service must still adhere to the prerequisites of the other declared types. For more information, see the Foreground services documentation.
বিশেষ ব্যবহার
- 要在清单中声明的前台服务类型
android:foregroundServiceTypespecialUse- 在清单中声明的权限
FOREGROUND_SERVICE_SPECIAL_USE- 要传递给
startForeground()的常量 FOREGROUND_SERVICE_TYPE_SPECIAL_USE- 运行时前提条件
- 无
- 说明
涵盖其他前台服务类型未涵盖的所有有效前台服务用例。
除了声明
FOREGROUND_SERVICE_TYPE_SPECIAL_USE前台服务类型之外,开发者还应在清单中声明用例。为此,他们会在<service>元素内指定<property>元素。这些值和相应的应用场景 。用途 您提供的案例均为自由形式,因此,您应确保提供足够的 相关信息,让审核人员了解您为何需要使用specialUse类型。<service android:name="fooService" android:foregroundServiceType="specialUse"> <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" android:value="explanation_for_special_use"/> </service>
সিস্টেম অব্যাহতি
- Foreground service type to declare in manifest under
android:foregroundServiceTypesystemExempted- Permission to declare in your manifest
FOREGROUND_SERVICE_SYSTEM_EXEMPTED- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED- Runtime prerequisites
- None
- Description
Reserved for system applications and specific system integrations, to continue to use foreground services.
To use this type, an app must meet at least one of the following criteria:
- Device is in demo mode state
- App is a Device Owner
- App is a Profiler Owner
- Safety Apps that have the
ROLE_EMERGENCYrole - Device Admin apps
- Apps holding
SCHEDULE_EXACT_ALARMorUSE_EXACT_ALARMpermission and are using Foreground Service to continue alarms in the background, including haptics-only alarms. VPN apps (configured using Settings > Network & Internet > VPN)
Otherwise, declaring this type causes the system to throw a
ForegroundServiceTypeNotAllowedException.
ফোরগ্রাউন্ড পরিষেবার প্রকারগুলি ব্যবহার করার জন্য Google Play নীতি প্রয়োগ
如果您的应用以 Android 14 或更高版本为目标平台,您需要在 Play 管理中心的“应用内容”页面(政策 > 应用内容)中声明应用的前台服务类型。如需详细了解如何在 Play 管理中心内声明前台服务类型,请参阅了解前台服务和全屏 intent 要求。