/** 显示带进度条通知栏 */ public void showProgressNotify() { mBuilder.setContentTitle("等待下载").setContentText("进度:").setTicker("开始下载"); // 通知首次出现在通知栏,带上升动画效果的 if (indeterminate) { // 不确定进度的 mBuilder.setProgress(0, 0, true); } else { // 确定进度的 mBuilder.setProgress(100, progress, false); // 这个方法是显示进度条 设置为true就是不确定的那种进度条效果 } mNotificationManager.notify(notifyId, mBuilder.build()); }
private NotificationCompat.Builder createDefaultNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); Intent onClick = new Intent(); onClick.setClassName( getPackageName(), /*Aptoide.getConfiguration().*/ getStartActivityClass().getName()); // TODO dependency injection onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.setAction(Intent.ACTION_VIEW); onClick.putExtra("fromDownloadNotification", true); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity( getApplicationContext(), 0, onClick, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setOngoing(true); mBuilder .setContentTitle( getString(R.string.aptoide_downloading, Aptoide.getConfiguration().getMarketName())) .setSmallIcon(R.drawable.stat_sys_download) .setProgress(0, 0, true) .setContentIntent(onClickAction); mBuilder.setProgress(100, 0, true); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(-3, mBuilder.build()); return mBuilder; }
private Notification getNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.launcher_icon) .setContentTitle("SleepMinder is active") .setContentText("Sleep well :)"); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setProgress(0, 0, true); mBuilder.setCategory(NotificationCompat.CATEGORY_PROGRESS); mBuilder.setOngoing(true); PendingIntent stopTrackingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.addAction(R.drawable.ic_action_stop, "Stop tracking", stopTrackingIntent); return mBuilder.build(); }
public void updateNotificationProgress(float progress) { if (mTotalMediaItems == 0) { return; } // Simple way to show progress of entire post upload // Would be better if we could get total bytes for all media items. double currentChunkProgress = (mItemProgressSize * progress) / 100; if (mCurrentMediaItem > 1) { currentChunkProgress += mItemProgressSize * (mCurrentMediaItem - 1); } mNotificationBuilder.setProgress(100, (int) Math.ceil(currentChunkProgress), false); try { mNotificationManager.notify(mNotificationId, mNotificationBuilder.build()); } catch (RuntimeException runtimeException) { CrashlyticsUtils.logException( runtimeException, CrashlyticsUtils.ExceptionType.SPECIFIC, AppLog.T.UTILS, "See issue #2858"); AppLog.d(T.POSTS, "See issue #2858; notify failed with:" + runtimeException); } }
private void postExecute() { taskIsRunning = false; builder.setContentTitle("Search complete!"); builder.setContentText("Jimp3 found " + songsAdded + " new songs."); // Removes the progress bar builder.setProgress(0, 0, false); notification.notify(id, builder.build()); stopSelf(); }
private void publishResults( String a, int p1, int p2, int id, long total, long done, boolean b, boolean move) { if (hash.get(id)) { mBuilder.setProgress(100, p1, false); mBuilder.setOngoing(true); int title = R.string.copying; if (move) title = R.string.moving; mBuilder.setContentTitle(utils.getString(c, title)); mBuilder.setContentText( new File(a).getName() + " " + utils.readableFileSize(done) + "/" + utils.readableFileSize(total)); int id1 = Integer.parseInt("456" + id); mNotifyManager.notify(id1, mBuilder.build()); if (p1 == 100 || total == 0) { mBuilder.setContentTitle("Copy completed"); if (move) mBuilder.setContentTitle("Move Completed"); mBuilder.setContentText(""); mBuilder.setProgress(0, 0, false); mBuilder.setOngoing(false); mBuilder.setAutoCancel(true); mNotifyManager.notify(id1, mBuilder.build()); publishCompletedResult(id, id1); } DataPackage intent = new DataPackage(); intent.setName(a); intent.setTotal(total); intent.setDone(done); intent.setId(id); intent.setP1(p1); intent.setP2(p2); intent.setMove(move); intent.setCompleted(b); hash1.put(id, intent); if (progressListener != null) { progressListener.onUpdate(intent); if (b) progressListener.refresh(); } } else publishCompletedResult(id, Integer.parseInt("456" + id)); }
private void preExecute() { taskIsRunning = true; notification = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); builder = new NotificationCompat.Builder(getApplicationContext()); builder.setContentTitle("Searching for new music..."); builder.setContentText("Looking for music files..."); builder.setSmallIcon(R.drawable.ic_launcher); builder.setProgress(100, 0, true); notification.notify(id, builder.build()); }
// type private void updateProgress(int type, int progress) { // Start a lengthy operation in a background thread /** 发送广播给ui activity */ downloadProgress = progress; intent.putExtra("progress", progress); intent.putExtra("type", type); sendBroadcast(intent); switch (type) { case DOWN_ERROR: mBuilder .setContentText("文件下载失败!") .setContentIntent(null) // Removes the progress bar .setProgress(0, 0, false); mNotifyManager.notify(0, mBuilder.build()); break; case DOWN_OK: mBuilder .setContentText("文件下载完成!") // Removes the progress bar .setProgress(0, 0, false); mNotifyManager.notify(0, mBuilder.build()); /** 取消之前的notification 新建 */ mNotifyManager.cancel(0); Intent okIntent = new Intent(this, DownLoadActivity.class); okIntent.putExtra("fileName", filename); okIntent.putExtra("fileDir", FileUtil.fileDir.toString()); okIntent.putExtra("progress", 100); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 1, okIntent, PendingIntent.FLAG_CANCEL_CURRENT); mBuilder = new NotificationCompat.Builder(this); mBuilder .setContentTitle(filename + "下载完成") .setContentText("文件下载完成,点击打开!!") .setContentIntent(notifyPendingIntent) .setAutoCancel(true) .setSmallIcon(R.mipmap.ic_launcher); mNotifyManager.notify(1, mBuilder.build()); break; case DOWNLOADING: mBuilder.setProgress(100, progress, false); mBuilder.setContentText("下载进度:" + progress + "%"); downloadProgress = progress; // 发送Action为com.example.communication.RECEIVER的广播 mNotifyManager.notify(0, mBuilder.build()); break; } }
public UploadImage(AppCompatActivity activity, String imageUri) { mActivity = activity; mImageUri = imageUri; mNotifyManager = (NotificationManager) mActivity.getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(mActivity); mBuilder .setContentTitle("Posting The Issue...") .setContentText("0%") .setSmallIcon(R.drawable.bullhorn_white); mBuilder.setAutoCancel(false); mBuilder.setOngoing(true); mBuilder.setProgress(100, 0, false); mNotifyManager.notify(id, mBuilder.build()); }
private static Notification updateUpdateStatusNotification( final Context context, final NotificationCompat.Builder builder, final int progress, final ParcelableStatusUpdate status) { builder.setContentTitle(context.getString(R.string.updating_status_notification)); if (status != null) { builder.setContentText(status.text); } builder.setSmallIcon(R.drawable.ic_stat_send); builder.setProgress(100, progress, progress >= 100 || progress <= 0); builder.setOngoing(true); return builder.build(); }
private static Notification updateSendDirectMessageNotification( final Context context, final NotificationCompat.Builder builder, final int progress, final String message) { builder.setContentTitle(context.getString(R.string.sending_direct_message)); if (message != null) { builder.setContentText(message); } builder.setSmallIcon(R.drawable.ic_stat_send); builder.setProgress(100, progress, progress >= 100 || progress <= 0); builder.setOngoing(true); return builder.build(); }
private NotificationCompat.Builder setNotification(final long id) { DownloadInfoRunnable info = getDownload(id); final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); // TODO Intent onClick = new Intent(); onClick.setClassName( getPackageName(), /*Aptoide.getConfiguration().*/ getStartActivityClass().getName()); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.setAction(Intent.ACTION_VIEW); onClick.putExtra("fromDownloadNotification", true); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity( getApplicationContext(), 0, onClick, PendingIntent.FLAG_UPDATE_CURRENT); int size = DownloadUtils.dpToPixels(getApplicationContext(), 36); Bitmap icon = null; try { // icon = // DownloadUtils.decodeSampledBitmapFromResource(ImageLoader.getInstance().getDiscCache().get(info.getDownload().getIcon()).getAbsolutePath(), size, size); icon = GlideUtils.downloadOnlyFromCache( Aptoide.getContext(), info.getDownload().getIcon(), size, size); } catch (Exception e) { e.printStackTrace(); } mBuilder.setOngoing(true); mBuilder.setContentTitle( getString(R.string.aptoide_downloading, Aptoide.getConfiguration().getMarketName())); mBuilder.setContentText(info.getDownload().getName()); if (icon != null) mBuilder.setLargeIcon(icon); mBuilder.setSmallIcon(android.R.drawable.stat_sys_download); mBuilder.setProgress(0, 0, true); mBuilder.setContentIntent(onClickAction); // Log.d("download-trace", "ETA: " + info.getEta()); if (info.getEta() > 0) { String remaining = DownloadUtils.formatEta(info.getEta(), ""); mBuilder.setContentInfo("ETA: " + (!remaining.equals("") ? remaining : "0s")); } return mBuilder; }
@Override public void didReceivedNotification(int id, Object... args) { if (id == NotificationCenter.FileUploadProgressChanged) { String fileName = (String) args[0]; if (path != null && path.equals(fileName)) { Float progress = (Float) args[1]; Boolean enc = (Boolean) args[2]; currentProgress = (int) (progress * 100); builder.setProgress(100, currentProgress, currentProgress == 0); NotificationManagerCompat.from(ApplicationLoader.applicationContext) .notify(4, builder.build()); } } else if (id == NotificationCenter.stopEncodingService) { String filepath = (String) args[0]; if (filepath == null || filepath.equals(path)) { stopSelf(); } } }
/** * 方法描述:createNotification方法 * * @see DownloadService */ public void createNotification() { Intent resultIntent = new Intent(this, DownLoadActivity.class); resultIntent.putExtra("fileName", filename); resultIntent.putExtra("fileDir", FileUtil.fileDir.toString()); resultIntent.putExtra("progress", downloadProgress); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); mBuilder .setContentTitle("下载文件" + filename) .setContentIntent(notifyPendingIntent) .setSmallIcon(R.mipmap.ic_launcher); mBuilder.setProgress(100, 0, false); mBuilder.setContentText("下载进度:" + 0 + "%"); mNotifyManager.notify(0, mBuilder.build()); }
public int onStartCommand(Intent intent, int flags, int startId) { path = intent.getStringExtra("path"); if (path == null) { stopSelf(); return Service.START_NOT_STICKY; } FileLog.e("tmessages", "start video service"); if (builder == null) { builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext); builder.setSmallIcon(android.R.drawable.stat_sys_upload); builder.setWhen(System.currentTimeMillis()); builder.setContentTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setTicker(LocaleController.getString("SendingVideo", R.string.SendingVideo)); builder.setContentText(LocaleController.getString("SendingVideo", R.string.SendingVideo)); } currentProgress = 0; builder.setProgress(100, currentProgress, currentProgress == 0); startForeground(4, builder.build()); NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build()); return Service.START_NOT_STICKY; }
@Override protected void onHandleIntent(Intent intent) { mNotifyManager = (NotificationManager) getApplication().getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); id++; mBuilder.setContentTitle(getResources().getString(R.string.working)); // mBuilder.setContentText(getResources().getString(R.string.workingU)); mBuilder.setSmallIcon(R.drawable.ic_action_not_secure); mBuilder.setProgress(0, 0, true); mBuilder.setOngoing(true); startForeground(id, mBuilder.build()); if (intent != null) { int idC = intent.getExtras().getInt(Constants.CRYPTO_CONTROLLER); manejarMedia(idC); // manejarMediaParalelo(idC); } mNotifyManager.cancel(id); }
protected void updateFinish(Context context) { if (mOnUpdateFinishListener != null) { mOnUpdateFinishListener.onFinish(); } mBuilder .setProgress(0, 0, false) .setContentTitle("更新完成") .setContentText("点击安装") .setOngoing(false) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_SOUND) .setContentIntent( getInstallIntent(context, Notification.FLAG_AUTO_CANCEL | PendingIntent.FLAG_ONE_SHOT)) .setSmallIcon(mUpdateFinishIconId); Notification notification = mBuilder.build(); mNotificationManager.notify(1, notification); // 更新缓存信息 updateCache(context, save_path + "/" + apkName); }
public Notification createNotification() { mNotifyBuild = new NotificationCompat.Builder(mController.getApplicationContext()) .setContentTitle(mController.getString(R.string.balatafm)) .setSmallIcon(R.drawable.ic_notification) .setContentIntent(getPendingIntent()); mNotifyBuild.setContentText(getNotificationString()); if (mPlayerState.isBuffering()) { mNotifyBuild.setProgress(0, 0, true); } else { if (mPlayerState.isPlaying()) { mNotifyBuild.addAction(R.drawable.player_stop, "Stop", getBroadcastIntent("stop")); mNotifyBuild.setOngoing(true); } else { mNotifyBuild.addAction(R.drawable.player_play, "Play", getBroadcastIntent("play")); } } mNotificationVisible = true; return mNotifyBuild.build(); }
private void showNotification(JSONObject message) { NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); // These attributes are required final String id; try { builder.setContentTitle(message.getString(TITLE_ATTR)); builder.setContentText(message.getString(TEXT_ATTR)); id = message.getString(ID_ATTR); } catch (JSONException ex) { Log.i(LOGTAG, "Error parsing", ex); return; } Uri imageUri = Uri.parse(message.optString(SMALLICON_ATTR)); builder.setSmallIcon(BitmapUtils.getResource(imageUri, R.drawable.ic_status_logo)); JSONArray light = message.optJSONArray(LIGHT_ATTR); if (light != null && light.length() == 3) { try { builder.setLights(light.getInt(0), light.getInt(1), light.getInt(2)); } catch (JSONException ex) { Log.i(LOGTAG, "Error parsing", ex); } } boolean ongoing = message.optBoolean(ONGOING_ATTR); builder.setOngoing(ongoing); if (message.has(WHEN_ATTR)) { long when = message.optLong(WHEN_ATTR); builder.setWhen(when); } if (message.has(PRIORITY_ATTR)) { int priority = message.optInt(PRIORITY_ATTR); builder.setPriority(priority); } if (message.has(LARGE_ICON_ATTR)) { Bitmap b = BitmapUtils.getBitmapFromDataURI(message.optString(LARGE_ICON_ATTR)); builder.setLargeIcon(b); } if (message.has(PROGRESS_VALUE_ATTR) && message.has(PROGRESS_MAX_ATTR) && message.has(PROGRESS_INDETERMINATE_ATTR)) { try { final int progress = message.getInt(PROGRESS_VALUE_ATTR); final int progressMax = message.getInt(PROGRESS_MAX_ATTR); final boolean progressIndeterminate = message.getBoolean(PROGRESS_INDETERMINATE_ATTR); builder.setProgress(progressMax, progress, progressIndeterminate); } catch (JSONException ex) { Log.i(LOGTAG, "Error parsing", ex); } } JSONArray actions = message.optJSONArray(ACTIONS_ATTR); if (actions != null) { try { for (int i = 0; i < actions.length(); i++) { JSONObject action = actions.getJSONObject(i); final PendingIntent pending = buildButtonClickPendingIntent(message, action); final String actionTitle = action.getString(ACTION_TITLE_ATTR); final Uri actionImage = Uri.parse(action.optString(ACTION_ICON_ATTR)); builder.addAction( BitmapUtils.getResource(actionImage, R.drawable.ic_status_logo), actionTitle, pending); } } catch (JSONException ex) { Log.i(LOGTAG, "Error parsing", ex); } } PendingIntent pi = buildNotificationPendingIntent(message, CLICK_EVENT); builder.setContentIntent(pi); PendingIntent deletePendingIntent = buildNotificationPendingIntent(message, CLEARED_EVENT); builder.setDeleteIntent(deletePendingIntent); GeckoAppShell.notificationClient.add(id.hashCode(), builder.build()); boolean persistent = message.optBoolean(PERSISTENT_ATTR); // We add only not persistent notifications to the list since we want to purge only // them when geckoapp is destroyed. if (!persistent && !mClearableNotifications.containsKey(id)) { mClearableNotifications.put(id, message.toString()); } }
@Override public Builder setProgress(int max, int progress, boolean indeterminate) { super.setProgress(max, progress, indeterminate); return this; }
@Override protected void onProgressUpdate(Integer... values) { mBuilder.setProgress(100, values[0], false).setContentText(values[0] + "%"); mNotifyManager.notify(id, mBuilder.build()); }
@Override protected void onHandleIntent(Intent intent) { mIsRunning = true; NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationBuilder.setSmallIcon(R.drawable.ic_update_service); notificationBuilder.setContentTitle(getString(R.string.app_name)); notificationBuilder.setContentText(getString(R.string.title_data_loading)); notificationBuilder.setAutoCancel(false); notificationBuilder.setContentIntent( PendingIntent.getActivity(this, 0, new Intent(this, RoutesActivity.class), 0)); notificationBuilder.setProgress(0, 0, true); Notification n = notificationBuilder.build(); n.flags |= Notification.FLAG_NO_CLEAR; notificationManager.notify(UPDATE_NOTIFICATION_ID, n); String link = String.format(URL_FORMAT, currentRegion.toString(), ROUTE_TAGS, ROUTE_META); ArrayList<WayRoute> routes = null; try { routes = new WebAPI().parseTransitInfoByUrl(new URL(link)); } catch (MalformedURLException e) { e.printStackTrace(); } if (routes != null) { // save to db DatabaseSource db = new DatabaseSource(this); db.open(); db.beginTransaction(); db.clear(); int added = 0; int index = 0; ContentValues pointValues = new ContentValues(); for (WayRoute route : routes) { // ignore routes out of city if (route.insideCity( currentRegion.Top, currentRegion.Left, currentRegion.Bottom, currentRegion.Right) && route.name != null) { long routeId = db.insertRoute( route.id, route.getName(), route.route, route.genDescription(), route.genPath()); if (routeId == -1) Log.e(RoutesActivity.class.getName(), "Can't add item"); for (Node node : route.getNodes()) { pointValues.put(RoutesContract.PointData.ROUTE_ID, routeId); pointValues.put(RoutesContract.PointData.LATITUDE, node.lat); pointValues.put(RoutesContract.PointData.LONGITUDE, node.lon); db.insertNode(pointValues); } added++; notificationBuilder.setProgress(routes.size(), index++, false); notificationManager.notify(UPDATE_NOTIFICATION_ID, notificationBuilder.build()); } } Log.d(RoutesActivity.class.getName(), "Routes addded to db: " + added); db.endTransaction(); db.close(); } notificationManager.cancel(UPDATE_NOTIFICATION_ID); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_UPDATED)); mIsRunning = false; }
@Override protected void onHandleIntent(Intent intent) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification) .setProgress(100, 0, false) .setOngoing(true) .setContentTitle(getResources().getString(R.string.loading_offline_whatif)) .setAutoCancel(true); NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotificationManager.notify(1, mBuilder.build()); PrefHelper prefHelper = new PrefHelper(getApplicationContext()); File sdCard = prefHelper.getOfflinePath(); File dir = new File(sdCard.getAbsolutePath() + OFFLINE_WHATIF_OVERVIEW_PATH); OkHttpClient client = new OkHttpClient(); Document doc; if (!dir.exists()) dir.mkdirs(); // download overview if (!BuildConfig.DEBUG) { try { doc = Jsoup.connect("https://what-if.xkcd.com/archive/") .userAgent( "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.19 Safari/537.36") .get(); StringBuilder sb = new StringBuilder(); Elements titles = doc.select("h1"); prefHelper.setNewestWhatif(titles.size()); sb.append(titles.first().text()); titles.remove(0); for (Element title : titles) { sb.append("&&"); sb.append(title.text()); } prefHelper.setWhatIfTitles(sb.toString()); Elements img = doc.select("img.archive-image"); int count = 1; for (Element image : img) { String url = image.absUrl("src"); try { Request request = new Request.Builder().url(url).build(); Response response = client.newCall(request).execute(); File file = new File(dir, String.valueOf(count) + ".png"); BufferedSink sink = Okio.buffer(Okio.sink(file)); sink.writeAll(response.body().source()); sink.close(); response.body().close(); } catch (Exception e) { e.printStackTrace(); } int p = (int) (count / ((float) img.size()) * 100); mBuilder.setProgress(100, p, false); mNotificationManager.notify(1, mBuilder.build()); count++; } if (prefHelper.getNewestWhatIf() == 0) prefHelper.setNewestWhatif(count - 1); } catch (IOException e) { e.printStackTrace(); } // download html int size = prefHelper.getNewestWhatIf(); for (int i = 1; i <= size; i++) { try { doc = Jsoup.connect("https://what-if.xkcd.com/" + String.valueOf(i)).get(); dir = new File(sdCard.getAbsolutePath() + OFFLINE_WHATIF_PATH + String.valueOf(i)); dir.mkdirs(); File file = new File(dir, String.valueOf(i) + ".html"); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(doc.outerHtml()); writer.close(); // download images int count = 1; for (Element e : doc.select(".illustration")) { try { String url = "http://what-if.xkcd.com" + e.attr("src"); Request request = new Request.Builder().url(url).build(); Response response = client.newCall(request).execute(); dir = new File(sdCard.getAbsolutePath() + OFFLINE_WHATIF_PATH + String.valueOf(i)); if (!dir.exists()) dir.mkdirs(); file = new File(dir, String.valueOf(count) + ".png"); BufferedSink sink = Okio.buffer(Okio.sink(file)); sink.writeAll(response.body().source()); sink.close(); response.body().close(); count++; } catch (Exception e2) { Log.e("article" + i, e2.getMessage()); } } int p = (int) (i / ((float) size) * 100); mBuilder.setProgress(100, p, false); mBuilder.setContentText(i + "/" + size); mNotificationManager.notify(1, mBuilder.build()); } catch (Exception e) { Log.e("article" + i, e.getMessage()); } } } prefHelper.setSunbeamLoaded(); Intent restart = new Intent("de.tap.easy_xkcd.ACTION_COMIC"); restart.putExtra("number", prefHelper.getLastComic()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, restart, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder .setContentIntent(pendingIntent) .setContentText(getResources().getString(R.string.not_restart)); mNotificationManager.notify(1, mBuilder.build()); }
/** * 更新通知栏进度 * * @param progress 更新进度,max为100 */ protected void updateNotificationPorgress(int progress) { mBuilder.setProgress(100, progress, false).setDefaults(0); Notification notification = mBuilder.build(); mNotificationManager.notify(1, notification); }
/** 设置下载进度 */ public void setNotify(int progress) { mBuilder.setProgress(100, progress, false); // 这个方法是显示进度条 mNotificationManager.notify(notifyId, mBuilder.build()); }
@Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { mIsCancelled = false; final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false); final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false); final boolean initialize = extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false); final int type = extras.getInt(SyncService.EXTRA_SYNC_TYPE, SyncService.FLAG_SYNC_ALL); LOGI( TAG, "Beginning sync for account " + account.name + "," + " uploadOnly=" + uploadOnly + " manualSync=" + manualSync + " initialize=" + initialize + ", type=" + type); if (initialize) { ContentResolver.setIsSyncable(account, authority, 1); ContentResolver.setSyncAutomatically(account, authority, true); Bundle b = new Bundle(); ContentResolver.addPeriodicSync(account, authority, b, 8 * 60 * 60); // 8 hours } if (!shouldContinueSync(uploadOnly)) { return; } toggleReceiver(true); mShowNotifications = PreferencesUtils.getSyncShowNotifications(mContext); NotificationCompat.Builder builder = createNotificationBuilder(); List<SyncTask> tasks = createTasks(mContext, type); for (int i = 0; i < tasks.size(); i++) { if (mIsCancelled) { showError(mContext.getString(R.string.sync_notification_error_cancel), null); break; } mCurrentTask = tasks.get(i); try { if (mShowNotifications) { builder.setProgress(tasks.size(), i, true); builder.setContentText(mContext.getString(mCurrentTask.getNotification())); NotificationCompat.InboxStyle detail = new NotificationCompat.InboxStyle(builder); detail.setSummaryText( String.format( mContext.getString(R.string.sync_notification_step_summary), i + 1, tasks.size())); for (int j = i; j >= 0; j--) { detail.addLine(mContext.getString(tasks.get(j).getNotification())); } NotificationUtils.notify(mContext, NotificationUtils.ID_SYNC, builder); } mCurrentTask.execute(mContext, account, syncResult); } catch (Exception e) { LOGE(TAG, "Syncing " + mCurrentTask, e); syncResult.stats.numIoExceptions++; showError(e); } } toggleReceiver(false); NotificationUtils.cancel(mContext, NotificationUtils.ID_SYNC); }
@Override public void onTransferred(int percentage) { mBuilder.setProgress(100, percentage, false); mBuilder.setContentInfo(percentage + "%"); mManager.notify(mNotificationId, mBuilder.build()); }
@Override public void onProgressChanged(int maxProgress, int currentProgress) { builder.setProgress(maxProgress, currentProgress, false); builder.setContentText("Adding songs to library"); notification.notify(id, builder.build()); }