本文整理汇总了Java中android.app.job.JobParameters类的典型用法代码示例。如果您正苦于以下问题:Java JobParameters类的具体用法?Java JobParameters怎么用?Java JobParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JobParameters类属于android.app.job包,在下文中一共展示了JobParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStartJob
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
public boolean onStartJob(JobParameters params){
DataBase data=DataBase.getInstance(getApplicationContext());
ActivityManager activityManager=(ActivityManager) getApplicationContext().getSystemService(getApplicationContext().ACTIVITY_SERVICE);
final List<ActivityManager.RunningAppProcessInfo> info=activityManager.getRunningAppProcesses();
if(info != null){
for(final ActivityManager.RunningAppProcessInfo process : info){
if(data.findInfo(process.processName)==1){
Intent service=new Intent(getApplicationContext(),UnlockActivity.class);
getApplicationContext().startService(service);
}
}
}
Util.Job(getApplicationContext());
return true;
}
示例2: onStartJob
import android.app.job.JobParameters; //导入依赖的package包/类
/**
* Callback when service start, here is when we execute our
* task in background, so an intensive task
* needs to run in another thread because
* this callback it executes on UI Thread
* @param params Are the parameters with was built
* the job
* @return true for execute the code
*/
@Override
public boolean onStartJob(final JobParameters params) {
Log.d("ONSTART","onstart");
//We set context and initialize the GNSDK API if it was not before.
if(ConnectivityDetector.sIsConnected) {
//GnService.API_INITIALIZED_AFTER_CONNECTED flag indicates
//that service was not initialized from Splash.
//is useful to inform to user in MainActivity
//that API of GNSDK has been initialized
GnService.withContext(getApplicationContext()).initializeAPI(GnService.API_INITIALIZED_AFTER_CONNECTED);
}
//if is connected, we finalize this job
jobFinished(params, !ConnectivityDetector.sIsConnected);
return true;
}
示例3: onStartJob
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
public boolean onStartJob(final JobParameters params) {
// I am on the main thread, so if you need to do background work,
// be sure to start up an AsyncTask, Thread, or IntentService!
final AppClass app = (AppClass) getApplication();
if (app.userIsLogged(false))
new Thread(new Runnable() {
@Override
public void run() {
NotificationsUtils.run(getBaseContext(), app);
jobFinished(params, true);
}
}).start();
else
jobFinished(params, false);
return true;
}
示例4: onStartJob
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
public boolean onStartJob(JobParameters params) {
Xlog.d(TAG, "Quote downloader job started");
if (params.getJobId() != JobUtils.JOB_ID) {
Xlog.e(TAG, "Job ID mismatch, ignoring");
return false;
}
if (!JobUtils.shouldRefreshQuote(this)) {
Xlog.d(TAG, "Should not refresh quote now, ignoring");
return false;
}
mUpdaterTask = new ServiceQuoteDownloaderTask(params);
mUpdaterTask.execute();
return true;
}
示例5: doInBackground
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
protected List<DiscountItem> doInBackground(JobParameters... params) {
JobParameters jobParams = params[0];
Log.i(TAG, "Poll Smzdm for new product");
List<DiscountItem> items;
if (mQuery == null) {
items = new SmzdmFetchr().fetchHomeDiscounts(1, "");
} else {
items = new SmzdmFetchr().searchDiscounts(0, mQuery);
}
jobFinished(jobParams, false);
return items;
}
示例6: 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;
}
}
示例7: onPostExecute
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
protected void onPostExecute(Result<JobParameters> result) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(jobService);
NotificationManager nm = (NotificationManager) jobService.
getSystemService(jobService.NOTIFICATION_SERVICE);
builder.setSmallIcon( android.R.drawable.sym_def_app_icon);
if ( result.exc!=null ) {
jobService.jobFinished(result.result, true);
builder.setContentTitle("Failed to sync account")
.setContentText("Failed to sync account " + result.exc);
} else{
builder.setContentTitle("Account Updated")
.setContentText("Updated Account Sucessfully at " + new Date().toString());
jobService.jobFinished(result.result, false);
}
nm.notify(NOTIFICACTION_ID, builder.build());
}
示例8: onStartJob
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
public boolean onStartJob(final JobParameters params) {
Log.d(TAG, "onStartJob: Start job");
task = new RuleDatabaseUpdateTask(this, FileHelper.loadCurrentSettings(this), true) {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
jobFinished(params, task.pendingCount() > 0);
}
@Override
protected void onCancelled(Void aVoid) {
super.onCancelled(aVoid);
jobFinished(params, task.pendingCount() > 0);
}
};
task.execute();
return false;
}
示例9: doInBackground
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
protected JobParameters[] doInBackground(JobParameters... params) {
this.params = params[0];
// mCurrentCharacter = new Character();
// PersistableBundle bundle = mParams.getExtras();
//
// mCurrentCharacter.setCharacterId(bundle.getLong(Constants.CHARACTER_ID));
// mCurrentCharacter.setCharacterName(bundle.getString(Constants.CHARACTER_NAME));
// mCurrentCharacter.setKeyId(bundle.getString(Constants.KEYID));
// mCurrentCharacter.setvCode(bundle.getString(Constants.VCODE));
//
// mApiService = new Api.Builder()
// .setTranquilityEndpoint()
// .build();
//
// mApiService.getMailHeaders(mCurrentCharacter, this);
// Do updating and stopping logical here.
return params;
}
示例10: onStartJob
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
public boolean onStartJob(JobParameters params) {
Log.i(getClass().getName(), "onStartJob");
// Start processing work
boolean isWifiEnabled = ConnectivityHelper.isWifiEnabled(getApplicationContext());
Log.i(getClass().getName(), "isWifiEnabled: " + isWifiEnabled);
boolean isWifiConnected = ConnectivityHelper.isWifiConnected(getApplicationContext());
Log.i(getClass().getName(), "isWifiConnected: " + isWifiConnected);
if (!isWifiEnabled) {
// Toast.makeText(getApplicationContext(), getString(R.string.wifi_needs_to_be_enabled), Toast.LENGTH_SHORT).show();
Log.i(getClass().getName(), getString(R.string.wifi_needs_to_be_enabled));
} else if (!isWifiConnected) {
// Toast.makeText(getApplicationContext(), getString(R.string.wifi_needs_to_be_connected), Toast.LENGTH_SHORT).show();
Log.i(getClass().getName(), getString(R.string.wifi_needs_to_be_connected));
} else {
new ReadDeviceAsyncTask(getApplicationContext()).execute();
}
boolean isWorkProcessingPending = false;
return isWorkProcessingPending;
}
示例11: doInBackground
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
protected JobParameters doInBackground(JobParameters... jobParameterses) {
Log.d(TAG, "We are running in MyTask in Job with ID: " + jobParameterses[0].getJobId());
int retry = 0;
while (!isCancelled() && retry < 10) {
try {
retry++;
Log.d(TAG, "Sleeping " + retry + "/10");
Thread.sleep(2 * 1000);
} catch (Exception e) {
Log.d(TAG, "Sleep has been interrupted");
}
}
Log.d(TAG, "We are " + (isCancelled()?"not ":"") + "done with Job");
if (isCancelled()) jobFinished(jobParameterses[0], true);
return jobParameterses[0];
}
示例12: onStartJob
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
public boolean onStartJob(JobParameters jobParameters) {
Log.i(TAG, "Start params=" + jobParameters);
Intent intent = new Intent(this, BackgroundService.class);
int id = jobParameters.getJobId();
if (id == JOB_UPLOAD_GPX) {
intent.setAction(BackgroundService.ACTION_UPLOAD_GPX);
intent.putExtras(Util.getBundle(jobParameters.getExtras()));
} else if (id == JOB_CONNECTIVITY)
intent.setAction(BackgroundService.ACTION_CONNECTIVITY);
else
Log.w(TAG, "Unknown job id=" + id);
Log.i(TAG, "Starting intent=" + intent);
startService(intent);
return false;
}
示例13: 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;
}
示例14: onStartJob
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
public boolean onStartJob(JobParameters params) {
ThreadUtils.assertOnUiThread();
BackgroundTask backgroundTask =
BackgroundTaskSchedulerJobService.getBackgroundTaskFromJobParameters(params);
if (backgroundTask == null) {
Log.w(TAG, "Failed to start task. Could not instantiate class.");
return false;
}
mCurrentTasks.put(params.getJobId(), backgroundTask);
TaskParameters taskParams =
BackgroundTaskSchedulerJobService.getTaskParametersFromJobParameters(params);
boolean taskNeedsBackgroundProcessing = backgroundTask.onStartTask(getApplicationContext(),
taskParams, new TaskFinishedCallbackJobService(this, backgroundTask, params));
if (!taskNeedsBackgroundProcessing) mCurrentTasks.remove(params.getJobId());
return taskNeedsBackgroundProcessing;
}
示例15: onStopJob
import android.app.job.JobParameters; //导入依赖的package包/类
@Override
public boolean onStopJob(JobParameters params) {
ThreadUtils.assertOnUiThread();
if (!mCurrentTasks.containsKey(params.getJobId())) {
Log.w(TAG, "Failed to stop job, because job with job id " + params.getJobId()
+ " does not exist.");
return false;
}
BackgroundTask backgroundTask = mCurrentTasks.get(params.getJobId());
TaskParameters taskParams =
BackgroundTaskSchedulerJobService.getTaskParametersFromJobParameters(params);
boolean taskNeedsReschedule =
backgroundTask.onStopTask(getApplicationContext(), taskParams);
mCurrentTasks.remove(params.getJobId());
return taskNeedsReschedule;
}