ফোরগ্রাউন্ড পরিষেবার ধরন

অ্যান্ড্রয়েড ১৪ (এপিআই লেভেল ৩৪) থেকে শুরু করে, আপনাকে প্রতিটি ফোরগ্রাউন্ড পরিষেবার জন্য একটি উপযুক্ত পরিষেবার ধরণ ঘোষণা করতে হবে। এর অর্থ হল আপনাকে আপনার অ্যাপ ম্যানিফেস্টে পরিষেবার ধরণ ঘোষণা করতে হবে এবং সেই ধরণের জন্য উপযুক্ত ফোরগ্রাউন্ড পরিষেবার অনুমতিও অনুরোধ করতে হবে ( FOREGROUND_SERVICE অনুমতির অনুরোধ ছাড়াও)। অধিকন্তু, ফোরগ্রাউন্ড পরিষেবার ধরণের উপর নির্ভর করে, পরিষেবাটি চালু করার আগে আপনাকে রানটাইম অনুমতির জন্য অনুরোধ করতে হতে পারে।

ক্যামেরা

Foreground service type to declare in manifest under android:foregroundServiceType
camera
Permission to declare in your manifest
FOREGROUND_SERVICE_CAMERA
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_CAMERA
Runtime prerequisites

Request and be granted the CAMERA runtime permission

Description

Continue to access the camera from the background, such as video chat apps that allow for multitasking.

সংযুক্ত ডিভাইস

ফোরগ্রাউন্ড সার্ভিস টাইপ যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
android:foregroundServiceType
connectedDevice
আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
FOREGROUND_SERVICE_CONNECTED_DEVICE
startForeground() এ পাস করার জন্য ধ্রুবক
FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE
রানটাইম পূর্বশর্ত

নিম্নলিখিত শর্তগুলির মধ্যে অন্তত একটি সত্য হতে হবে:

বর্ণনা

ব্লুটুথ, এনএফসি, আইআর, ইউএসবি বা নেটওয়ার্ক সংযোগের প্রয়োজন বাহ্যিক ডিভাইসগুলির সাথে মিথস্ক্রিয়া।

বিকল্প

যদি আপনার অ্যাপটিকে একটি বাহ্যিক ডিভাইসে ক্রমাগত ডেটা স্থানান্তর করতে হয়, তবে পরিবর্তে সহচর ডিভাইস ম্যানেজার ব্যবহার করার কথা বিবেচনা করুন। সহচর ডিভাইসের পরিসরে থাকাকালীন আপনার অ্যাপটি চলমান থাকতে সাহায্য করার জন্য সহচর ডিভাইস উপস্থিতি API ব্যবহার করুন৷

আপনার অ্যাপটিকে ব্লুটুথ ডিভাইসের জন্য স্ক্যান করার প্রয়োজন হলে, পরিবর্তে ব্লুটুথ স্ক্যান API ব্যবহার করার কথা বিবেচনা করুন।

ডেটা সিঙ্ক

ম্যানিফেস্টে ঘোষণা করার জন্য ফোরগ্রাউন্ড পরিষেবার ধরণ
android:foregroundServiceType
dataSync
আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
FOREGROUND_SERVICE_DATA_SYNC
startForeground() এ পাস করার জন্য ধ্রুবক
FOREGROUND_SERVICE_TYPE_DATA_SYNC
রানটাইম পূর্বশর্ত
কোনটিই নয়
বিবরণ

ডেটা ট্রান্সফার অপারেশন, যেমন নিম্নলিখিত:

  • ডেটা আপলোড বা ডাউনলোড
  • ব্যাকআপ-এবং-পুনরুদ্ধার কার্যক্রম
  • আমদানি বা রপ্তানি কার্যক্রম
  • তথ্য আনুন
  • স্থানীয় ফাইল প্রক্রিয়াকরণ
  • একটি নেটওয়ার্কের মাধ্যমে একটি ডিভাইস এবং ক্লাউডের মধ্যে ডেটা স্থানান্তর করুন
বিকল্প

বিস্তারিত তথ্যের জন্য ডেটা সিঙ্ক ফোরগ্রাউন্ড পরিষেবার বিকল্পগুলি দেখুন।

স্বাস্থ্য

Foreground service type to declare in manifest under
android:foregroundServiceType
health
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:

Description

Any long-running use cases to support apps in the fitness category such as exercise trackers.

স্থান

Foreground service type to declare in manifest under
android:foregroundServiceType
location
Permission to declare in your manifest
FOREGROUND_SERVICE_LOCATION
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_LOCATION
Runtime prerequisites

The user must have enabled location services and the app must be granted at least one of the following runtime permissions:

Description

Long-running use cases that require location access, such as navigation and location sharing.

Alternatives

If your app needs to be triggered when the user reaches specific locations, consider using the geofence API instead.

মিডিয়া

ম্যানিফেস্টে ঘোষণা করার জন্য ফোরগ্রাউন্ড পরিষেবার ধরণ
android:foregroundServiceType
mediaPlayback
আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
FOREGROUND_SERVICE_MEDIA_PLAYBACK
startForeground() এ পাস করার জন্য ধ্রুবক
FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
রানটাইম পূর্বশর্ত
কোনটিই নয়
বিবরণ

ব্যাকগ্রাউন্ড থেকে অডিও বা ভিডিও প্লেব্যাক চালিয়ে যান। অ্যান্ড্রয়েড টিভিতে ডিজিটাল ভিডিও রেকর্ডিং (DVR) কার্যকারিতা সমর্থন করুন।

বিকল্প

যদি আপনি ছবিতে ভিডিও দেখান, তাহলে ছবিতে ছবিতে মোড ব্যবহার করুন।

মিডিয়া প্রক্রিয়াকরণ

Foreground service type to declare in manifest under
android:foregroundServiceType
mediaProcessing
Permission to declare in your manifest
FOREGROUND_SERVICE_MEDIA_PROCESSING
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING
Runtime prerequisites
None
Description

Service for performing time-consuming operations on media assets, like converting media to different formats. The system allows this service a limited time to run; under normal circumstances, this time limit would be 6 hours out of every 24. (This limit is shared by all of an app's mediaProcessing foreground services.)

Your app should manually stop the media processing service in the following scenario:

If the timeout period is reached, the system calls the service's Service.onTimeout(int, int) method. At this time, the service has a few seconds to call Service.stopSelf(). If the service does not call Service.stopSelf(), an ANR will occur with this error message: "A foreground service of <fgs_type> did not stop within its timeout: <component_name>".

Note: Service.onTimeout(int, int) is not available on Android 14 or lower. On devices running those versions, if a media processing service reaches the timeout period, the system immediately caches the app. For this reason, your app shouldn't wait to get a timeout notification. Instead, it should terminate the foreground service or change it to a background service as soon as appropriate.

মিডিয়া প্রক্ষেপণ

ম্যানিফেস্টে ঘোষণা করার জন্য ফোরগ্রাউন্ড পরিষেবার ধরণ
android:foregroundServiceType
mediaProjection
আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
FOREGROUND_SERVICE_MEDIA_PROJECTION
startForeground() এ পাস করার জন্য ধ্রুবক
FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
রানটাইম পূর্বশর্ত

ফোরগ্রাউন্ড পরিষেবা শুরু করার আগে createScreenCaptureIntent() পদ্ধতিটি কল করুন। এটি করলে ব্যবহারকারীকে একটি অনুমতির বিজ্ঞপ্তি দেখানো হবে; পরিষেবাটি তৈরি করার আগে ব্যবহারকারীকে অনুমতি দিতে হবে।

ফোরগ্রাউন্ড পরিষেবা তৈরি করার পরে, আপনি MediaProjectionManager.getMediaProjection() কল করতে পারেন।

বিবরণ

MediaProjection এপিআই ব্যবহার করে নন-প্রাইমারি ডিসপ্লে বা এক্সটার্নাল ডিভাইসে কন্টেন্ট প্রজেক্ট করুন। এই কন্টেন্টটি কেবল মিডিয়া কন্টেন্ট হতে হবে না।

বিকল্প

অন্য ডিভাইসে মিডিয়া স্ট্রিম করতে, Google Cast SDK ব্যবহার করুন।

মাইক্রোফোন

Foreground service type to declare in manifest under
android:foregroundServiceType
microphone
Permission to declare in your manifest
FOREGROUND_SERVICE_MICROPHONE
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_MICROPHONE
Runtime prerequisites

Request and be granted the RECORD_AUDIO runtime permission.

Description

Continue microphone capture from the background, such as voice recorders or communication apps.

ফোন কল

ম্যানিফেস্টে ঘোষণা করার জন্য ফোরগ্রাউন্ড পরিষেবার ধরণ
android:foregroundServiceType
phoneCall
আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
FOREGROUND_SERVICE_PHONE_CALL
startForeground() এ পাস করার জন্য ধ্রুবক
FOREGROUND_SERVICE_TYPE_PHONE_CALL
রানটাইম পূর্বশর্ত

এই শর্তগুলির মধ্যে অন্তত একটি সত্য হতে হবে:

  • অ্যাপটি তার ম্যানিফেস্ট ফাইলে MANAGE_OWN_CALLS অনুমতি ঘোষণা করেছে।
  • ROLE_DIALER ভূমিকার মাধ্যমে অ্যাপটি ডিফল্ট ডায়ালার অ্যাপ।
বিবরণ

ConnectionService API ব্যবহার করে একটি চলমান কল চালিয়ে যান।

বিকল্প

যদি আপনার ফোন, ভিডিও বা ভিওআইপি কল করার প্রয়োজন হয়, তাহলে android.telecom লাইব্রেরি ব্যবহার করার কথা বিবেচনা করুন।

কল স্ক্রিন করার জন্য CallScreeningService ব্যবহার করার কথা বিবেচনা করুন।

দূরবর্তী বার্তাপ্রেরণ

Foreground service type to declare in manifest under
android:foregroundServiceType
remoteMessaging
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:foregroundServiceType
shortService
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_SERVICE permission.
  • A shortService can 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 shortService at 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 call Service.stopSelf() or Service.stopForeground() before the timeout occurs. Otherwise, the new Service.onTimeout() is called, giving apps a brief opportunity to call stopSelf() or stopForeground() 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 mentions FOREGROUND_SERVICE_TYPE_SHORT_SERVICE. For these reasons, it's considered best practice to implement the Service.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 the Service.onTimeout() callback yet.

It's important to note that if the timeout of the shortService is 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 the FOREGROUND_SERVICE_TYPE_SHORT_SERVICE parameter 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 a ForegroundServiceStartNotAllowedException.

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 shortService type and another foreground service type, the system ignores the shortService type declaration. However, the service must still adhere to the prerequisites of the other declared types. For more information, see the Foreground services documentation.

বিশেষ ব্যবহার

Foreground service type to declare in manifest under
android:foregroundServiceType
specialUse
Permission to declare in your manifest
FOREGROUND_SERVICE_SPECIAL_USE
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_SPECIAL_USE
Runtime prerequisites
None
Description

Covers any valid foreground service use cases that aren't covered by the other foreground service types.

In addition to declaring the FOREGROUND_SERVICE_TYPE_SPECIAL_USE foreground service type, developers should declare use cases in the manifest. To do so, they specify the <property> element within the <service> element. These values and corresponding use cases are reviewed when you submit your app in the Google Play Console. The use cases you provide are free-form, and you should make sure to provide enough information to let the reviewer see why you need to use the specialUse type.

<service android:name="fooService" android:foregroundServiceType="specialUse">
  <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
      android:value="explanation_for_special_use"/>
</service>

সিস্টেম অব্যাহতিপ্রাপ্ত

ফোরগ্রাউন্ড সার্ভিস টাইপ যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
android:foregroundServiceType
systemExempted
আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
FOREGROUND_SERVICE_SYSTEM_EXEMPTED
startForeground() এ পাস করার জন্য ধ্রুবক
FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED
রানটাইম পূর্বশর্ত
কোনোটিই নয়
বর্ণনা

ফোরগ্রাউন্ড পরিষেবাগুলি ব্যবহার করা চালিয়ে যাওয়ার জন্য সিস্টেম অ্যাপ্লিকেশন এবং নির্দিষ্ট সিস্টেম ইন্টিগ্রেশনের জন্য সংরক্ষিত।

এই ধরনের ব্যবহার করার জন্য, একটি অ্যাপকে অবশ্যই নিম্নলিখিত মানদণ্ডগুলির মধ্যে একটি পূরণ করতে হবে:

  • ডিভাইস ডেমো মোড অবস্থায় আছে
  • অ্যাপটি একটি ডিভাইসের মালিক
  • অ্যাপ একজন প্রোফাইলার মালিক
  • ROLE_EMERGENCY ভূমিকা আছে এমন নিরাপত্তা অ্যাপ
  • ডিভাইস অ্যাডমিন অ্যাপস
  • SCHEDULE_EXACT_ALARM বা USE_EXACT_ALARM অনুমতি ধারণ করা অ্যাপ
  • ভিপিএন অ্যাপস ( সেটিংস > নেটওয়ার্ক এবং ইন্টারনেট > ভিপিএন ব্যবহার করে কনফিগার করা হয়েছে)

    অন্যথায়, এই ধরনের ঘোষণা করার ফলে সিস্টেম একটি ForegroundServiceTypeNotAllowedException নিক্ষেপ করে।

ফোরগ্রাউন্ড পরিষেবার ধরণ ব্যবহারের জন্য Google Play নীতি প্রয়োগ

If your app targets Android 14 or higher, you'll need to declare your app's foreground service types in the Play Console's app content page (Policy > App content). For more information on how to declare your foreground service types in Play Console, see Understanding foreground service and full-screen intent requirements.