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

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

ডেটা সিঙ্ক

Foreground service type to declare in manifest under
android:foregroundServiceType
dataSync
Permission to declare in your manifest
FOREGROUND_SERVICE_DATA_SYNC
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_DATA_SYNC
Runtime prerequisites
None
Description

Data transfer operations, such as the following:

  • Data upload or download
  • Backup-and-restore operations
  • Import or export operations
  • Fetch data
  • Local file processing
  • Transfer data between a device and the cloud over a network
Alternatives

See Alternatives to data sync foreground services for detailed information.

স্বাস্থ্য

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

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

বর্ণনা

ব্যায়াম ট্র্যাকারের মতো ফিটনেস বিভাগে অ্যাপগুলিকে সমর্থন করার জন্য যেকোন দীর্ঘস্থায়ী ব্যবহারের ক্ষেত্রে।

স্থান

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.

মিডিয়া

Foreground service type to declare in manifest under
android:foregroundServiceType
mediaPlayback
Permission to declare in your manifest
FOREGROUND_SERVICE_MEDIA_PLAYBACK
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
Runtime prerequisites
None
Description

Continue audio or video playback from the background. Support Digital Video Recording (DVR) functionality on Android TV.

Alternatives

If you're showing picture-in-picture video, use Picture-in-Picture mode.

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

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.

ফোন কল

Foreground service type to declare in manifest under
android:foregroundServiceType
phoneCall
Permission to declare in your manifest
FOREGROUND_SERVICE_PHONE_CALL
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_PHONE_CALL
Runtime prerequisites

At least one of these conditions must be true:

  • App is the default dialer app through the ROLE_DIALER role.
Description

Continue an ongoing call using the ConnectionService APIs.

Alternatives

If you need to make phone, video, or VoIP calls, consider using the android.telecom library.

Consider using CallScreeningService to screen calls.

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

ফোরগ্রাউন্ড সার্ভিস টাইপ যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
android:foregroundServiceType
remoteMessaging
আপনার ম্যানিফেস্টে ঘোষণা করার অনুমতি
FOREGROUND_SERVICE_REMOTE_MESSAGING
startForeground() এ পাস করার জন্য ধ্রুবক
FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING
রানটাইম পূর্বশর্ত
কোনোটিই নয়
বর্ণনা
এক ডিভাইস থেকে অন্য ডিভাইসে পাঠ্য বার্তা স্থানান্তর করুন। কোনো ব্যবহারকারীর মেসেজিং কাজের ধারাবাহিকতায় সহায়তা করে যখন তারা ডিভাইসগুলি পরিবর্তন করে।

সংক্ষিপ্ত পরিষেবা

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

জটিল কাজ দ্রুত শেষ করুন যা বাধা বা স্থগিত করা যাবে না।

এই ধরনের কিছু অনন্য বৈশিষ্ট্য আছে:

  • শুধুমাত্র অল্প সময়ের জন্য চলতে পারে (প্রায় 3 মিনিট)।
  • স্টিকি ফোরগ্রাউন্ড পরিষেবাগুলির জন্য কোনও সমর্থন নেই।
  • অন্যান্য ফোরগ্রাউন্ড পরিষেবাগুলি শুরু করতে পারে না৷
  • টাইপ-নির্দিষ্ট অনুমতির প্রয়োজন হয় না, যদিও এটির জন্য এখনও FOREGROUND_SERVICE অনুমতি প্রয়োজন৷
  • একটি shortService শুধুমাত্র অন্য পরিষেবার প্রকারে পরিবর্তন করতে পারে যদি অ্যাপটি বর্তমানে একটি নতুন ফোরগ্রাউন্ড পরিষেবা শুরু করার যোগ্য হয়৷
  • একটি ফোরগ্রাউন্ড পরিষেবা যে কোনও সময় তার ধরনকে shortService পরিবর্তন করতে পারে, যে সময়ে টাইমআউট পিরিয়ড শুরু হয়।

Service.startForeground() বলা হওয়ার মুহুর্ত থেকে শর্টসার্ভিসের সময়সীমা শুরু হয়। সময় শেষ হওয়ার আগে অ্যাপটি Service.stopSelf() বা Service.stopForeground() কল করবে বলে আশা করা হচ্ছে। অন্যথায়, নতুন Service.onTimeout() কল করা হবে, অ্যাপগুলিকে তাদের পরিষেবা বন্ধ করতে stopSelf() বা stopForeground() কল করার একটি সংক্ষিপ্ত সুযোগ দেয়৷

Service.onTimeout() কল করার অল্প সময়ের পরে, অ্যাপটি একটি ক্যাশড অবস্থায় প্রবেশ করে এবং ব্যবহারকারী অ্যাপের সাথে সক্রিয়ভাবে ইন্টারঅ্যাক্ট না করা পর্যন্ত এটিকে আর অগ্রভাগে বিবেচনা করা হয় না। অ্যাপটি ক্যাশ করার কিছুক্ষণ পরে এবং পরিষেবা বন্ধ না হলে, অ্যাপটি একটি ANR পায়। ANR বার্তাটি FOREGROUND_SERVICE_TYPE_SHORT_SERVICE উল্লেখ করেছে। এই কারণগুলির জন্য, Service.onTimeout() কলব্যাক বাস্তবায়ন করা সর্বোত্তম অনুশীলন হিসাবে বিবেচিত হয়৷

Service.onTimeout() কলব্যাক Android 13 এবং তার নিচের সংস্করণে বিদ্যমান নেই। যদি একই পরিষেবা এই জাতীয় ডিভাইসগুলিতে চলে, তবে এটি একটি টাইমআউট পায় না এবং এটি ANRও করে না। নিশ্চিত করুন যে আপনার পরিষেবাটি প্রক্রিয়াকরণের কাজ শেষ করার সাথে সাথেই বন্ধ হয়ে যায়, এমনকি যদি এটি এখনও Service.onTimeout() কলব্যাক না পায়।

এটা মনে রাখা গুরুত্বপূর্ণ যে যদি shortService টাইমআউটকে সম্মান না করা হয়, তাহলে অ্যাপটি ANR করবে এমনকি এটির অন্যান্য বৈধ অগ্রভাগের পরিষেবা বা অন্যান্য অ্যাপ লাইফসাইকেল প্রক্রিয়া চলমান থাকলেও।

যদি কোনও অ্যাপ ব্যবহারকারীর কাছে দৃশ্যমান হয় বা ফোরগ্রাউন্ড পরিষেবাগুলিকে ব্যাকগ্রাউন্ড থেকে শুরু করার অনুমতি দেয় এমন ছাড়গুলির মধ্যে একটিকে সন্তুষ্ট করে, তাহলে FOREGROUND_SERVICE_TYPE_SHORT_SERVICE প্যারামিটারের সাথে আবার Service.StartForeground() কল করলে সময়সীমা আরও 3 মিনিট বৃদ্ধি করে৷ অ্যাপটি ব্যবহারকারীর কাছে দৃশ্যমান না হলে এবং ছাড়গুলির একটিকে সন্তুষ্ট না করলে, ধরন নির্বিশেষে অন্য ফোরগ্রাউন্ড পরিষেবা শুরু করার যে কোনও প্রচেষ্টা একটি ForegroundServiceStartNotAllowedException সৃষ্টি করে৷

যদি কোনও ব্যবহারকারী আপনার অ্যাপের জন্য ব্যাটারি অপ্টিমাইজেশান অক্ষম করে, তবে এটি এখনও শর্টসার্ভিস FGS-এর টাইমআউট দ্বারা প্রভাবিত হয়।

আপনি যদি একটি ফোরগ্রাউন্ড পরিষেবা শুরু করেন যাতে shortService টাইপ এবং অন্য ফোরগ্রাউন্ড পরিষেবার ধরন অন্তর্ভুক্ত থাকে, তবে সিস্টেমটি shortService টাইপ ঘোষণা উপেক্ষা করে। যাইহোক, পরিষেবাটিকে এখনও অন্যান্য ঘোষিত প্রকারের পূর্বশর্তগুলি মেনে চলতে হবে। আরও তথ্যের জন্য, ফোরগ্রাউন্ড পরিষেবার ডকুমেন্টেশন দেখুন।

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

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.