當前位置: 首頁>>代碼示例>>Java>>正文


Java JobParameters.getExtras方法代碼示例

本文整理匯總了Java中android.app.job.JobParameters.getExtras方法的典型用法代碼示例。如果您正苦於以下問題:Java JobParameters.getExtras方法的具體用法?Java JobParameters.getExtras怎麽用?Java JobParameters.getExtras使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.job.JobParameters的用法示例。


在下文中一共展示了JobParameters.getExtras方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onStartJob

import android.app.job.JobParameters; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public boolean onStartJob(JobParameters params) {
    try {
        if (sTaskPool == null)
            throw new NullPointerException("TaskJobService TaskPool not set!");
        BaseBundle bundle = params.getExtras();
        String taskName = bundle.getString(TaskScheduler.TASK_NAME);
        Task task = (Task) Class.forName(taskName).newInstance();
        ArrayMap<String, Object> map = new ArrayMap<>(bundle.size());
        for (String key : bundle.keySet()) {
            map.put(key, bundle.get(key));
        }
        task.deserialize(map);
        if (task instanceof HttpTask)
            Http.execute((HttpTask)task).addCallback(new JobCallback(params));
        else
            sTaskPool.execute(task).addCallback(new JobCallback(params));
        return true;
    } catch (Exception err) {
        LOG.e("Error running task", err);
        jobFinished(params, true);
        return false;
    }
}
 
開發者ID:lifechurch,項目名稱:nuclei-android,代碼行數:26,代碼來源:TaskJobService.java

示例2: onStartJob

import android.app.job.JobParameters; //導入方法依賴的package包/類
/**
 * Called when a Notification has been interacted with by the user. If we can verify that
 * the Intent has a notification Id, start Chrome (if needed) on the UI thread.
 *
 * We get a wakelock for our process for the duration of this method.
 *
 * @return True if there is more work to be done to handle the job, to signal we would like our
 * wakelock extended until we call {@link #jobFinished}. False if we have finished handling the
 * job.
 */
@Override
public boolean onStartJob(final JobParameters params) {
    PersistableBundle extras = params.getExtras();
    if (!extras.containsKey(NotificationConstants.EXTRA_NOTIFICATION_ID)
            || !extras.containsKey(NotificationConstants.EXTRA_NOTIFICATION_INFO_ORIGIN)
            || !extras.containsKey(NotificationConstants.EXTRA_NOTIFICATION_INFO_TAG)) {
        return false;
    }

    Intent intent =
            new Intent(extras.getString(NotificationConstants.EXTRA_NOTIFICATION_ACTION));
    intent.putExtras(new Bundle(extras));

    ThreadUtils.assertOnUiThread();
    NotificationService.dispatchIntentOnUIThread(this, intent);

    // TODO(crbug.com/685197): Return true here and call jobFinished to release the wake
    // lock only after the event has been completely handled by the service worker.
    return false;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:31,代碼來源:NotificationJobService.java

示例3: onStartJob

import android.app.job.JobParameters; //導入方法依賴的package包/類
@Override
public boolean onStartJob(JobParameters params) {
    PersistableBundle pb=params.getExtras();
    if (pb.getBoolean(JobSchedulerActivity.KEY_DOWNLOAD, false)) {
        Intent downloadService = new Intent (getApplicationContext(),DownloadService.class);
        downloadService.setData(Uri.parse(downloadLink));

        getApplicationContext().startService(downloadService);
        return true;
    }
    return false;
}
 
開發者ID:if710,項目名稱:2017.2-codigo,代碼行數:13,代碼來源:DownloadJobService.java

示例4: onStartJob

import android.app.job.JobParameters; //導入方法依賴的package包/類
@Override
public boolean onStartJob(JobParameters params) {
    this.params = params;
    setBooleanArray();
    context = getApplicationContext();

    PersistableBundle persistableBundle = params.getExtras();
    booleanArray = persistableBundle.getBooleanArray(NotificationFragment.BOOLEAN_CODE);
    updateBooleans();
    setApiCall();
    return true;

}
 
開發者ID:noisie74,項目名稱:SportsNewsHistoryRecords,代碼行數:14,代碼來源:JobSchedulerService.java

示例5: getTaskParametersFromJobParameters

import android.app.job.JobParameters; //導入方法依賴的package包/類
/**
 * Retrieves the {@link TaskParameters} from the {@link JobParameters}, which are passed as
 * one of the keys. Only values valid for {@link android.os.BaseBundle} are supported, and other
 * values are stripped at the time when the task is scheduled.
 *
 * @param jobParameters the {@link JobParameters} to extract the {@link TaskParameters} from.
 * @return the {@link TaskParameters} for the current job.
 */
static TaskParameters getTaskParametersFromJobParameters(JobParameters jobParameters) {
    TaskParameters.Builder builder = TaskParameters.create(jobParameters.getJobId());

    PersistableBundle jobExtras = jobParameters.getExtras();
    PersistableBundle persistableTaskExtras =
            jobExtras.getPersistableBundle(BACKGROUND_TASK_EXTRAS_KEY);

    Bundle taskExtras = new Bundle();
    taskExtras.putAll(persistableTaskExtras);
    builder.addExtras(taskExtras);

    return builder.build();
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:22,代碼來源:BackgroundTaskSchedulerJobService.java

示例6: onStartJob

import android.app.job.JobParameters; //導入方法依賴的package包/類
@Override
public boolean onStartJob(final JobParameters params) {
    final Context applicationContext = getApplicationContext();
    final SiteToSiteDB siteToSiteDB = new SiteToSiteDB(applicationContext);

    PersistableBundle extras = params.getExtras();
    final ParcelableQueuedOperationResultCallback parcelableQueuedOperationResultCallback = SerializationUtils.getParcelable(SiteToSiteJobService.class.getClassLoader(), extras, "callback");

    QueuedSiteToSiteClientConfig queuedSiteToSiteClientConfig = SerializationUtils.getParcelable(SiteToSiteJobService.class.getClassLoader(), extras, "config");
    try {
        siteToSiteDB.updatePeerStatusOnConfig(queuedSiteToSiteClientConfig);
    } catch (SQLiteIOException e) {
        parcelableQueuedOperationResultCallback.onException(applicationContext, e);
        jobFinished(params, true);
        return false;
    }

    SiteToSiteService.processQueuedPackets(applicationContext, queuedSiteToSiteClientConfig, new QueuedOperationResultCallback() {
        @Override
        public Handler getHandler() {
            return null;
        }

        @Override
        public void onSuccess() {
            if (parcelableQueuedOperationResultCallback != null) {
                parcelableQueuedOperationResultCallback.onSuccess(applicationContext);
            }
            jobFinished(params, false);
        }

        @Override
        public void onException(IOException exception) {
            if (parcelableQueuedOperationResultCallback != null) {
                parcelableQueuedOperationResultCallback.onException(applicationContext, exception);
            }
            jobFinished(params, true);
        }
    });
    return true;
}
 
開發者ID:hortonworks,項目名稱:nifi-android-s2s,代碼行數:42,代碼來源:SiteToSiteJobService.java

示例7: yourMethod

import android.app.job.JobParameters; //導入方法依賴的package包/類
private void yourMethod(JobParameters params) {
    Log.d(TAG,"yourMethod is executing");

    // TODO: Put the code that you want to execute

    /**
     * Your code
     */


    //retrieve duration and depending of previous time
    //set, establish new delay to execute your next method.
    PersistableBundle extraInfo = params.getExtras();
    int previousDuration = extraInfo.getInt("duration");
    int newSchedulingTime = 0;

    if(previousDuration ==  0) {
        newSchedulingTime = 7000;
    }
    else if(previousDuration == 7000){
        newSchedulingTime = 9000;
    }
    else if(previousDuration == 9000) {
        newSchedulingTime = 7000;
    }
    //pass true to re schedule current task,
    //false if not. In this case finish it.
    jobFinished(params, false);


    //After finish previous task,
    //re schedule new Job
    Log.d(TAG, "yourMethod is going to execute after " + newSchedulingTime + " " + getString(R.string.seconds) + "\n\n");
    Toast.makeText(this, getString(R.string.info) + newSchedulingTime + " " +getString(R.string.seconds), Toast.LENGTH_SHORT).show();

    //Send this intent with LocalBroadcastManager
    //this ensures safe communication because
    //the intents are sent only inside our application.
    //The intent will be sent inside our app and
    //processed by any interested component in our app
    //that has registered an IntentFilter with the action MainActivity.Constants.ACTION_UPDATE_UI,
    //in our case MainActivity.
    Intent intent = new Intent();
    intent.setAction(MainActivity.Constants.ACTION_UPDATE_UI);
    intent.putExtra(MainActivity.Constants.DURATION, newSchedulingTime);
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

    //Re schedule our task with new delay that it takes
    //to execute
    Job.scheduleJob(this, newSchedulingTime);
}
 
開發者ID:frank240889,項目名稱:JobSchedulerTest,代碼行數:52,代碼來源:PeriodicTaskService.java

示例8: getBackgroundTaskClassFromJobParameters

import android.app.job.JobParameters; //導入方法依賴的package包/類
private static String getBackgroundTaskClassFromJobParameters(JobParameters jobParameters) {
    PersistableBundle extras = jobParameters.getExtras();
    if (extras == null) return null;
    return extras.getString(BACKGROUND_TASK_CLASS_KEY);
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:6,代碼來源:BackgroundTaskSchedulerJobService.java


注:本文中的android.app.job.JobParameters.getExtras方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。