@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; }
/** * 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; }
@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; }
@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; }
@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; }
@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; } }
@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()); }
@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; }
@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; }
@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; }
@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]; }
@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; }
/** * 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; }
@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; }
@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; }
@Override public boolean onStartJob(JobParameters params) { Context appCtx = getApplicationContext(); if (appCtx instanceof DSCApplication) { DSCApplication application = (DSCApplication) appCtx; MediaContentJobService.log(appCtx, Log.DEBUG, TAG, "onStartJob()"); Uri[] uris = params.getTriggeredContentUris(); if (Utilities.isEmpty(uris)) { application.rescheduleMediaContentJobService(); } else { if (!application.isRenameFileTaskRunning()) { application.launchAutoRenameTask(null, false, null, true); } } } return true; }
@Override public boolean onStartJob(JobParameters params) { context = this; notificationManagerCompat = NotificationManagerCompat.from(context); preferences = PreferenceManager.getDefaultSharedPreferences(context); if (!preferences.getBoolean(AutoCleanSettingsActivity.PREF_AUTO_CLEAN, false)) return false; sendNotification(); cleanUp(); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); new Handler().postDelayed(new Runnable() { @Override public void run() { Log.v(MyUtil.PACKAGE_NAME, getString(R.string.toast_auto_clean, deletedFileCount)); Toast.makeText( context, getString(R.string.toast_auto_clean, deletedFileCount), Toast.LENGTH_SHORT ).show(); notificationManagerCompat.cancel(NOTIFICATION_JOB_ID); } }, 3000); return true; }
@Override public boolean onStartJob(JobParameters params) { if (DEBUG) { Log.d(TAG, "onStartJob(" + params.getJobId() + ")"); } // Broadcast status Intent intent = new Intent(ACTION_SYNC_STATUS_CHANGED); intent.putExtra(BUNDLE_KEY_INPUT_ID, params.getExtras().getString(BUNDLE_KEY_INPUT_ID)); intent.putExtra(SYNC_STATUS, SYNC_STARTED); LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); EpgSyncTask epgSyncTask = new EpgSyncTask(params); synchronized (mTaskArray) { mTaskArray.put(params.getJobId(), epgSyncTask); } epgSyncTask.execute(); return true; }
@Override public boolean onStartJob(JobParameters params) { ProviderUpdateRequester providerUpdateRequester = new ProviderUpdateRequester(this, new ComponentName(this, ArtworkComplicationProviderService.class)); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); Set<String> complicationSet = preferences.getStringSet( ArtworkComplicationProviderService.KEY_COMPLICATION_IDS, new TreeSet<>()); if (!complicationSet.isEmpty()) { int[] complicationIds = new int[complicationSet.size()]; int index = 0; for (String complicationId : complicationSet) { complicationIds[index++] = Integer.parseInt(complicationId); } if (BuildConfig.DEBUG) { Log.d(TAG, "Job running, updating " + complicationSet); } providerUpdateRequester.requestUpdate(complicationIds); } // Schedule the job again to catch the next update to the artwork scheduleComplicationUpdateJob(this); return false; }
@Override public boolean onStartJob(final JobParameters params) { BackgroundFetch adapter = BackgroundFetch.getInstance(getApplicationContext()); if (adapter.isMainActivityActive()) { return true; } adapter.registerCompletionHandler(new FetchJobService.CompletionHandler() { @Override public void finish() { Log.d(BackgroundFetch.TAG, "HeadlessJobService jobFinished"); jobFinished(params, false); } }); Log.d(BackgroundFetch.TAG, "HeadlessJobService onStartJob"); new BackgroundFetchHeadlessTask().onFetch(getApplicationContext()); return true; }
@Override public boolean onStartJob(final JobParameters jobParameters) { mWorkerHandler.post(new Runnable() { @Override public void run() { WallpaperManager wallpaperManager = WallpaperManager.getInstance( ColorExtractionService.this); int wallpaperId = ExtractionUtils.getWallpaperId(wallpaperManager); ExtractedColors extractedColors = new ExtractedColors(); if (wallpaperManager.getWallpaperInfo() != null) { // We can't extract colors from live wallpapers; always use the default color. extractedColors.updateHotseatPalette(null); } else { // We extract colors for the hotseat and status bar separately, // since they only consider part of the wallpaper. extractedColors.updateHotseatPalette(getHotseatPalette()); if (PreferencesState.isLightStatusBarPrefEnabled(getBaseContext())) { extractedColors.updateStatusBarPalette(getStatusBarPalette()); } } // Save the extracted colors and wallpaper id to LauncherProvider. String colorsString = extractedColors.encodeAsString(); Bundle extras = new Bundle(); extras.putInt(LauncherSettings.Settings.EXTRA_WALLPAPER_ID, wallpaperId); extras.putString(LauncherSettings.Settings.EXTRA_EXTRACTED_COLORS, colorsString); getContentResolver().call( LauncherSettings.Settings.CONTENT_URI, LauncherSettings.Settings.METHOD_SET_EXTRACTED_COLORS_AND_WALLPAPER_ID, null, extras); jobFinished(jobParameters, false /* needsReschedule */); } }); return true; }
@Override public boolean onStartJob(JobParameters params) { Log.d(TAG, "onStartJob(): params = [" + params + "]"); Intent intent = new Intent(getApplicationContext(), DaemonService.class); startService(intent); jobFinished(params, false); return false; }
@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; }
@Override public boolean onStartJob(JobParameters params) { LogUtil.d(TAG,"onStartJob"); startService(new Intent(JobService.this,BigBangMonitorService.class)); startService(new Intent(JobService.this,ListenClipboardService.class)); return false; }
@Override public boolean onStopJob(JobParameters params) { LogUtil.d(TAG,"onStopJob"); startService(new Intent(JobService.this,BigBangMonitorService.class)); startService(new Intent(JobService.this,ListenClipboardService.class)); return false; }
@Override public boolean onStartJob(JobParameters job) { ParentObject parentObject = LoginDAB.parentObject; LoginStore store = LoginFactory.getLoginFactory().getStore(StaticInfo.NETWORK_TYPE, null); store.save(parentObject, this.getBaseContext()); return true; }
@Override public boolean onStartJob(JobParameters params) { if (DEBUG) { Log.d(TAG, "onStartJob(" + params.getJobId() + ")"); } EpgSyncTask epgSyncTask = new EpgSyncTask(params); synchronized (mTaskArray) { mTaskArray.put(params.getJobId(), epgSyncTask); } epgSyncTask.execute(); return true; }
@Override public boolean onStopJob(JobParameters params) { synchronized (mTaskArray) { int jobId = params.getJobId(); EpgSyncTask epgSyncTask = mTaskArray.get(jobId); if (epgSyncTask != null) { epgSyncTask.cancel(true); mTaskArray.delete(params.getJobId()); } } return false; }
private void finishEpgSync(JobParameters jobParams) { if (DEBUG) { Log.d(TAG, "taskFinished(" + jobParams.getJobId() + ")"); } mTaskArray.delete(jobParams.getJobId()); jobFinished(jobParams, false); if (jobParams.getJobId() == SyncUtils.REQUEST_SYNC_JOB_ID) { Intent intent = new Intent(ACTION_SYNC_STATUS_CHANGED); intent.putExtra( BUNDLE_KEY_INPUT_ID, jobParams.getExtras().getString(BUNDLE_KEY_INPUT_ID)); intent.putExtra(SYNC_STATUS, SYNC_FINISHED); LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); } }
@Override public boolean onStartJob(final JobParameters params) { Intent intent = new Intent(SCHEDULER_FLUSHER_INTENT); intent.putExtra(START_JOB_INTENT_KEY, ON_START_INTENT_EXTRA); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); return false; }
@Override public boolean onStopJob(final JobParameters params) { Intent intent = new Intent(SCHEDULER_FLUSHER_INTENT); intent.putExtra(STOP_JOB_INTENT_KEY, ON_ERROR_INTENT_EXTRA); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); return true; }
@Override public boolean onStopJob(JobParameters jobParameters) { if (mSynchronizeDatabaseTask != null) { mSynchronizeDatabaseTask.cancel(true); mSynchronizeDatabaseTask = null; } return true; }
@Override public boolean onStartJob(JobParameters jobParameters) { AddWatchNextContinueInBackground newTask = new AddWatchNextContinueInBackground( jobParameters); newTask.execute(); return true; }
@Override public boolean onStartJob(JobParameters jobParameters) { DeleteWatchNextContinueInBackground newTask = new DeleteWatchNextContinueInBackground( jobParameters); newTask.execute(); return true; }
@Override public void stopJob(JobParameters jobParams) throws RemoteException { int jobId = jobParams.getJobId(); synchronized (mJobSessions) { JobSession session = mJobSessions.get(jobId); if (session != null) { session.stopSession(); } } }
/** * This method should not be called by the application manually. * @param jobParameters The JobParameters are generated by the QuickPeriodicJobScheduler based off the id and interval * @return Return true because the job is async */ @Override public boolean onStartJob(final JobParameters jobParameters) { // Get the jobId int id = jobParameters.getJobId(); // Find the job in the collection QuickPeriodicJob job = getQuickPeriodicJob(id); if(job != null) { // Schedule job again long interval = jobParameters.getExtras().getLong("interval"); QuickPeriodicJobScheduler qpjs = new QuickPeriodicJobScheduler(this); qpjs.start(id, interval); // Run the job job.getJob().execute(new QuickJobFinishedCallback() { @Override public void jobFinished() { QuickPeriodicJobRunner.this.jobFinished(jobParameters, false); } }); } // Return if the job is async return true; }
@Test public void testRunnerReturns() { QuickPeriodicJobRunner qpjr = new QuickPeriodicJobRunner(); JobParameters jp = mock(JobParameters.class); doReturn(5).when(jp).getJobId(); Assert.assertTrue(qpjr.onStartJob(jp)); Assert.assertTrue(qpjr.onStopJob(jp)); }
@Override public boolean onStartJob(JobParameters params) { if(isNetworkConnected()){ // new WebDownLoadTask().execute(params); // Intent intent = new Intent(Intent.ACTION_VIEW); // intent.setData(Uri.parse("http://blog.csdn.net/qq_31726827/article/details/50462025")); // intent.setFlags(FLAG_ACTIVITY_NEW_TASK); // startActivity(intent); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); Notification notification = builder .setContentTitle("这是通知标题") .setContentText("这是通知内容") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .build(); manager.notify(1, notification); jobFinished(params,false); Log.e(TAG, "success"); return true; } Log.e(TAG, "fail"); return false; }
@Override public boolean onStartJob(JobParameters params) { Log.e("MyLog","onStartJob"); Integer jobId = params.getJobId(); ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); // Optional<String> optional = activityManager.getRunningServices(Integer.MAX_VALUE).stream() // .map((x) -> x.service.getClassName().toString()) // .filter(x -> x.equals(jobservie.get(jobId))).findFirst(); // if (!optional.isPresent()) { // System.out.println("begin recover needkeepservice!"); // Log.e("MyLog", "begin recover needkeepservice!22"); // startService(new Intent(this, NeedKeepService.class)); // // } for (ActivityManager.RunningServiceInfo serviceInfo : activityManager.getRunningServices(128)) { if (serviceInfo.service.getClassName().equals(jobservie.get(jobId))) { return true; } } Log.e("MyLog", "begin recover needkeepservice!"); startService(new Intent(this, NeedKeepService.class)); return true; }