次の方法で共有


JobService.SetNotification Method

Definition

Provide JobScheduler with a notification to post and tie to this job's lifecycle.

[Android.Runtime.Register("setNotification", "(Landroid/app/job/JobParameters;ILandroid/app/Notification;I)V", "", ApiSince=34)]
public void SetNotification (Android.App.Job.JobParameters params, int notificationId, Android.App.Notification notification, Android.App.Job.JobEndNotificationPolicy jobEndNotificationPolicy);
[<Android.Runtime.Register("setNotification", "(Landroid/app/job/JobParameters;ILandroid/app/Notification;I)V", "", ApiSince=34)>]
member this.SetNotification : Android.App.Job.JobParameters * int * Android.App.Notification * Android.App.Job.JobEndNotificationPolicy -> unit

Parameters

params
JobParameters

The parameters identifying this job, as supplied to the job in the #onStartJob(JobParameters) callback.

notificationId
Int32

The ID for this notification, as per android.app.NotificationManager#notify(int, Notification).

notification
Notification

The notification to be displayed.

jobEndNotificationPolicy
JobEndNotificationPolicy

The policy to apply to the notification when the job stops.

Attributes

Remarks

Provide JobScheduler with a notification to post and tie to this job's lifecycle. This is only required for those user-initiated jobs which return true via JobParameters#isUserInitiatedJob(). If the app does not call this method for a required notification within 10 seconds after #onStartJob(JobParameters) is called, the system will trigger an ANR and stop this job.

The notification must provide an accurate description of the work that the job is doing and, if possible, the state of the work.

Note that certain types of jobs (e.g. JobInfo.Builder#setEstimatedNetworkBytes(long, long) data transfer jobs) may require the notification to have certain characteristics and their documentation will state any such requirements.

JobScheduler will not remember this notification after the job has finished running, so apps must call this every time the job is started (if required or desired).

If separate jobs use the same notification ID with this API, the most recently provided notification will be shown to the user, and the jobEndNotificationPolicy of the last job to stop will be applied.

Java documentation for android.app.job.JobService.setNotification(android.app.job.JobParameters, int, android.app.Notification, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to