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

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

ক্যামেরা

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

CAMERA রানটাইম অনুমতির জন্য অনুরোধ করুন এবং তা মঞ্জুর করুন

বিবরণ

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

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

Foreground service type to declare in manifest under
android:foregroundServiceType
connectedDevice
Permission to declare in your manifest
FOREGROUND_SERVICE_CONNECTED_DEVICE
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE
Runtime prerequisites

At least one of the following conditions must be true:

Description

Interactions with external devices that require a Bluetooth, NFC, IR, USB, or network connection.

Alternatives

If your app needs to do continuous data transfer to an external device, consider using the companion device manager instead. Use the companion device presence API to help your app stay running while the companion device is in range.

If your app needs to scan for bluetooth devices, consider using the Bluetooth scan API instead.

ডেটা সিঙ্ক

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

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

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

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

স্বাস্থ্য

ফোরগ্রাউন্ড সার্ভিস টাইপ যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
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.

মিডিয়া

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

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

বিকল্প

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

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

ফোরগ্রাউন্ড পরিষেবার ধরন যা ম্যানিফেস্টের অধীনে ঘোষণা করতে হবে
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 এপিআই ব্যবহার করে নন-প্রাইমারি ডিসপ্লে বা এক্সটার্নাল ডিভাইসে কন্টেন্ট প্রজেক্ট করুন। এই কন্টেন্টটি কেবল মিডিয়া কন্টেন্ট হতে হবে না।

বিকল্প

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

মাইক্রোফোন

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

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

বিবরণ

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

ফোন কল

ম্যানিফেস্টে ঘোষণা করার জন্য ফোরগ্রাউন্ড পরিষেবার ধরণ
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.

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

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

যেকোন বৈধ ফোরগ্রাউন্ড পরিষেবা ব্যবহারের ক্ষেত্রে কভার করে যা অন্যান্য ফোরগ্রাউন্ড পরিষেবার ধরন দ্বারা কভার করা হয় না।

FOREGROUND_SERVICE_TYPE_SPECIAL_USE ফোরগ্রাউন্ড পরিষেবার ধরন ঘোষণা করার পাশাপাশি, বিকাশকারীদের ম্যানিফেস্টে ব্যবহারের কেসগুলি ঘোষণা করা উচিত৷ এটি করার জন্য, তারা <service> উপাদানের মধ্যে <property> উপাদানটি নির্দিষ্ট করে। আপনি যখন Google Play Console-এ আপনার অ্যাপ জমা দেন তখন এই মানগুলি এবং সংশ্লিষ্ট ব্যবহারের ক্ষেত্রে পর্যালোচনা করা হয়। আপনি যে ব্যবহারের ক্ষেত্রেগুলি প্রদান করেন তা ফ্রি-ফর্ম, এবং আপনাকে পর্যাপ্ত তথ্য প্রদানের বিষয়টি নিশ্চিত করতে হবে যাতে পর্যালোচক দেখতে পান কেন আপনাকে 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>

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

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

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

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

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

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

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

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