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

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

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

বর্ণনা

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

অবস্থান

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

ব্যবহারকারীর অবশ্যই লোকেশন পরিষেবা সক্রিয় থাকতে হবে এবং অ্যাপটিকে অবশ্যই নিম্নলিখিত রানটাইম অনুমতিগুলির মধ্যে অন্তত একটি মঞ্জুর করতে হবে:

বর্ণনা

দীর্ঘস্থায়ী ব্যবহারের ক্ষেত্রে যেখানে অবস্থান অ্যাক্সেসের প্রয়োজন হয়, যেমন নেভিগেশন এবং অবস্থান ভাগ করে নেওয়া।

বিকল্প

ব্যবহারকারী নির্দিষ্ট অবস্থানে পৌঁছালে আপনার অ্যাপটিকে ট্রিগার করার প্রয়োজন হলে, পরিবর্তে জিওফেন্স API ব্যবহার করার কথা বিবেচনা করুন।

মিডিয়া

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

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

বিকল্প

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

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

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

মিডিয়া সম্পদে সময়-সাপেক্ষ ক্রিয়াকলাপ সম্পাদনের জন্য পরিষেবা, যেমন মিডিয়াকে বিভিন্ন ফর্ম্যাটে রূপান্তর করা। সিস্টেমটি এই পরিষেবাটিকে সীমিত সময় চালানোর অনুমতি দেয়; সাধারণ পরিস্থিতিতে, এই সময়সীমা প্রতি 24টির মধ্যে 6 ঘন্টা হবে। (এই সীমাটি একটি অ্যাপের mediaProcessing ফোরগ্রাউন্ড পরিষেবাগুলির সমস্ত দ্বারা ভাগ করা হয়

নিম্নলিখিত পরিস্থিতিতে আপনার অ্যাপটিকে ম্যানুয়ালি মিডিয়া প্রক্রিয়াকরণ পরিষেবা বন্ধ করা উচিত:

  • যখন ট্রান্সকোডিং অপারেশন শেষ হয় বা ব্যর্থতার অবস্থায় পৌঁছায়, পরিষেবাটিকে সম্পূর্ণরূপে বন্ধ করতে Service.stopForeground() এবং Service.stopSelf() কল করুন৷

যদি টাইমআউট পিরিয়ড পৌঁছে যায়, সিস্টেম পরিষেবাটির Service.onTimeout(int, int) পদ্ধতিতে কল করে। এই সময়ে, পরিষেবাটিতে Service.stopSelf() কল করার জন্য কয়েক সেকেন্ড সময় আছে। যদি পরিষেবাটি Service.stopSelf() কে কল না করে, তাহলে এই ত্রুটি বার্তার সাথে একটি ANR ঘটবে: " <fgs_type> এর একটি অগ্রভাগের পরিষেবা তার সময়সীমার মধ্যে থামেনি: <component_name> "।

দ্রষ্টব্য : Service.onTimeout(int, int) Android 14 বা তার নিচের সংস্করণে উপলব্ধ নয়। সেই সংস্করণগুলি চলমান ডিভাইসগুলিতে, যদি কোনও মিডিয়া প্রক্রিয়াকরণ পরিষেবা সময়সীমার মধ্যে পৌঁছে যায়, সিস্টেমটি অবিলম্বে অ্যাপটিকে ক্যাশ করে। এই কারণে, আপনার অ্যাপের সময় শেষ হওয়ার বিজ্ঞপ্তি পাওয়ার জন্য অপেক্ষা করা উচিত নয়। পরিবর্তে, এটি ফোরগ্রাউন্ড পরিষেবাটি বন্ধ করা উচিত বা যত তাড়াতাড়ি উপযুক্ত হিসাবে এটি একটি ব্যাকগ্রাউন্ড পরিষেবাতে পরিবর্তন করা উচিত।

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

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

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

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

বর্ণনা

MediaProjection API ব্যবহার করে অপ্রধান ডিসপ্লে বা বাহ্যিক ডিভাইসে কন্টেন্ট প্রজেক্ট করুন। এই কন্টেন্টকে শুধুমাত্র মিডিয়া কন্টেন্ট হতে হবে এমন কোনো বাধ্যবাধকতা নেই।

বিকল্প

অন্য ডিভাইসে মিডিয়া স্ট্রিম করতে গুগল কাস্ট এসডিকে ব্যবহার করুন।

মাইক্রোফোন

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

RECORD_AUDIO রানটাইম পারমিশনের জন্য অনুরোধ করুন এবং তা মঞ্জুর করা হোক।

বর্ণনা

ভয়েস রেকর্ডার বা কমিউনিকেশন অ্যাপের মতো ডিভাইস থেকে ব্যাকগ্রাউন্ডে মাইক্রোফোন ক্যাপচার চালিয়ে যান।

ফোন কল

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
রানটাইম পূর্বশর্ত
কোনোটিই নয়
বর্ণনা
এক ডিভাইস থেকে অন্য ডিভাইসে পাঠ্য বার্তা স্থানান্তর করুন। কোনো ব্যবহারকারীর মেসেজিং কাজের ধারাবাহিকতায় সহায়তা করে যখন তারা ডিভাইসগুলি পরিবর্তন করে।

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

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 নিক্ষেপ করে।

ফোরগ্রাউন্ড সার্ভিস টাইপ ব্যবহারের জন্য গুগল প্লে-র নীতি প্রয়োগ

যদি আপনার অ্যাপটি Android 14 বা তার উচ্চতরকে টার্গেট করে, তাহলে আপনাকে Play Console-এর অ্যাপ কন্টেন্ট পৃষ্ঠায় ( নীতি > অ্যাপ সামগ্রী ) আপনার অ্যাপের ফোরগ্রাউন্ড পরিষেবার ধরন ঘোষণা করতে হবে। Play Console-এ আপনার ফোরগ্রাউন্ড পরিষেবার প্রকারগুলি কীভাবে ঘোষণা করবেন সে সম্পর্কে আরও তথ্যের জন্য, ফোরগ্রাউন্ড পরিষেবা এবং পূর্ণ-স্ক্রীনের অভিপ্রায়ের প্রয়োজনীয়তা বোঝা দেখুন।