Download Notifications actions

Download Notifications actions

How To Downgrade Any App On Android! (2020)
How To Downgrade Any App On Android! (2020)

I have an app that in part of this app downloads video files. I show the download in the notification in the status bar. and every notification has a cancel action button. in the first notification cancel action button enable but in another notification cancel action button is disabled!!!

please help me.

my classes:

private void DownloadMovie(String _link, String fileName) { BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(ProductDetails.this); bottomSheetDialog.setContentView(R.layout.dialog_startingdownload); bottomSheetDialog.setCancelable(true); MaterialButton reject_btn = bottomSheetDialog.findViewById(R.id.canceldw_btn); MaterialButton close_btn = bottomSheetDialog.findViewById(R.id.closeWindow); ProgressBar progressBar = bottomSheetDialog.findViewById(R.id.progressbar); TextView downloadingtxt = bottomSheetDialog.findViewById(R.id.txt); TextView progresstext = bottomSheetDialog.findViewById(R.id.progresstxt); TextView TVSizeDownload = bottomSheetDialog.findViewById(R.id.TVSizeDownload); TextView TVSizeTypeDownload = bottomSheetDialog.findViewById(R.id.TVSizeTypeDownload); TextView fileSizetxt = bottomSheetDialog.findViewById(R.id.fileSize); assert TVSizeDownload != null; TVSizeDownload.setVisibility(VISIBLE); assert TVSizeTypeDownload != null; TVSizeTypeDownload.setVisibility(VISIBLE); assert progresstext != null; progresstext.setVisibility(VISIBLE); assert downloadingtxt != null; downloadingtxt.setVisibility(VISIBLE); assert progressBar != null; progressBar.setVisibility(VISIBLE); assert reject_btn != null; reject_btn.setVisibility(VISIBLE); assert fileSizetxt != null; fileSizetxt.setVisibility(VISIBLE); assert close_btn != null; close_btn.setVisibility(VISIBLE); downloadManager = new ThinDownloadManager(1); retryPolicy = new DefaultRetryPolicy(); NewDownloadClass myDownloadStatusListener = new NewDownloadClass(downloadManager, progresstext, downloadingtxt, TVSizeDownload, TVSizeTypeDownload, pathdata, fileName, bottomSheetDialog, progressBar, "film", titleName, ProductDetails.this,lat,lng,product_id,user_id,token,os_ver,deviceName); Toast.makeText(this, "released"+"-"+downloadManager.isReleased(), Toast.LENGTH_SHORT).show(); myDownloadStatusListener.delegate = this; isDownloadCompleted = false; Uri downloadUri = Uri.parse(_link); Uri destinationUri = Uri.parse(pathdata + fileName); retryPolicy = new DefaultRetryPolicy(5000, 3, 2f); downloadingtxt.setText("downloading"); DownloadRequest downloadRequest = new DownloadRequest(downloadUri) .setRetryPolicy(retryPolicy) .setDestinationURI(destinationUri).setPriority(DownloadRequest.Priority.HIGH) .setDownloadContext("first")//Optional .setDeleteDestinationFileOnFailure(true) .setDownloadResumable(true) .setStatusListener(myDownloadStatusListener); if (downloadManager.query(downloadId) == DownloadManager.STATUS_NOT_FOUND) { downloadId = downloadManager.add(downloadRequest); } close_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bottomSheetDialog.dismiss(); } }); reject_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bottomSheetDialog.dismiss(); downloadManager.cancelAll(); if (new File(pathdata + fileName).exists()) if (new File(pathdata + fileName).delete()) { Log.e("DEL FILE FROM SD", "--ok"); } if (notificationId != 0) if (mNotifyManager != null) mNotifyManager.cancel(notificationId); isDownloadCompleted=true; } }); bottomSheetDialog.show(); }

my NewDownloadClass:

public class NewDownloadClass implements DownloadStatusListenerV1 { String type; BottomSheetDialog bottomSheetDialog; TextView downloadingtxt; TextView progresstext; TextView tvSizeDownload; TextView tvSizeTypeDownload; ProgressBar progressBar; public ThinDownloadManager downloadManager; public AsyncResponse delegate = null; ProgressDialog bar; static int i = 0; Activity activity; String link, id, name, path, unziplocate, state, notifName; private static String TAG = "MainActivity"; private NotificationManager mNotifyManager; private NotificationCompat.Builder mBuilder; DownloadClass downloadClass; String NOTIFICATION_CHANNEL_ID = "my_channel_id_01"; PendingIntent pendingIntent, dismissNotif; int notificationId = 0; String lat; String lng; String product_id; String user_id; String token; String os_ver; String deviceName; public NewDownloadClass(ThinDownloadManager downloadManager, TextView progresstext, TextView downloadingtxt, TextView tvSizeDownload, TextView tvSizeTypeDownload, String pathdata, String fileName, BottomSheetDialog bottomSheetDialog, ProgressBar progressBar, String film, String titleName, ProductDetails productDetails, String lat, String lng, String product_id, String user_id, String token, String os_ver, String deviceName) { this.downloadManager = downloadManager; this.bottomSheetDialog = bottomSheetDialog; this.downloadingtxt = downloadingtxt; this.progresstext = progresstext; this.progressBar = progressBar; this.tvSizeDownload = tvSizeDownload; this.tvSizeTypeDownload = tvSizeTypeDownload; // this.bar = progress; this.link = link; this.path = pathdata; this.name = fileName; this.state = film; this.notifName = titleName; this.activity = productDetails; this.lat = lat; this.lng = lng; this.product_id = product_id; this.user_id = user_id; this.token = token; this.os_ver = os_ver; this.deviceName = deviceName; // this.mNotifyManager=mNotifyManager; // this.mBuilder=mBuilder; // this.notificationId=notificationId; preparAndShowDownload(); } private void preparAndShowDownload() { notificationId = new Random().nextInt(); // just use a counter in some util class... //behtare id khode file bashe ke uniqe // for open activity Intent intent = new Intent(activity, ProductDetails.class); //todo intent put extra //todo check in below android 6 and api 23 intent.putExtra("lat", lat); intent.putExtra("lng", lng); intent.putExtra("product_id", product_id); intent.putExtra("user_id", user_id); intent.putExtra("token", token); intent.putExtra("os_ver", os_ver); intent.putExtra("deviceName", deviceName); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { pendingIntent = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } mNotifyManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, notifName, importance); mNotifyManager.createNotificationChannel(notificationChannel); mBuilder = new NotificationCompat.Builder(activity, notificationChannel.getId()); } else { mBuilder = new NotificationCompat.Builder(activity); } ButtonReceiver.downloadManager = downloadManager; Intent buttonIntent = new Intent(activity, ButtonReceiver.class); buttonIntent.putExtra("notificationId", notificationId); buttonIntent.putExtra("file", path + name); dismissNotif = PendingIntent.getBroadcast(activity, 0, buttonIntent, PendingIntent.FLAG_CANCEL_CURRENT); mBuilder = mBuilder .setSmallIcon(R.drawable.ic_comica_about_logo) .setColor(ContextCompat.getColor(activity, R.color.ocher)) .setContentTitle("downloading") .setOnlyAlertOnce(true) .setProgress(0, 0, false) .setDefaults(Notification.DEFAULT_ALL) .setPriority(Notification.PRIORITY_DEFAULT) .setAutoCancel(true) .setContentIntent(pendingIntent) .addAction(R.drawable.ic_close_notif, "انصراف", dismissNotif) .setLargeIcon(BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_comica_about_logo)); mNotifyManager.notify(notificationId, mBuilder.build()); } @Override public void onDownloadComplete(DownloadRequest downloadRequest) { progressBar.setVisibility(View.GONE); downloadManager.release(); bottomSheetDialog.dismiss(); delegate.processFinish(true); downloadingtxt.setText("دانلود کامل شد."); mBuilder .setContentTitle("دانلود تمام شد") .setContentText("") // Removes the progress bar .setProgress(0, 0, false); mNotifyManager.notify(notificationId, mBuilder.build()); if (notificationId != 0) mNotifyManager.cancel(notificationId); } @Override public void onDownloadFailed(DownloadRequest downloadRequest, int errorCode, String errorMessage) { progressBar.setProgress(0); if (activity != null && !activity.isFinishing()) bottomSheetDialog.dismiss(); downloadManager.cancelAll(); File file = new File(path + name); if (file.exists()) if (file.delete()) Log.e("failed del sd", "--ok--" + path + name); else Log.e("failed del sd", "--NOT ok--" + path + name); if (notificationId != 0) mNotifyManager.cancel(notificationId); delegate.allowDownload(true); } @Override public void onProgress(DownloadRequest downloadRequest, long totalBytes, long downloadedBytes, int progress) { progressBar.setProgress(progress); progresstext.setText(progress + "%"); int size = (int) ((totalBytes / 1024) / 1024); String type; if (size < 1) { size = (int) (totalBytes / (1024)); type = " KB"; } else { type = " MB"; } tvSizeDownload.setText(String.valueOf(size)); tvSizeTypeDownload.setText(type); mBuilder .setSubText(progress + "%") .setProgress(100, progress, false); mNotifyManager.notify(notificationId, mBuilder.build()); } }

You are viewing this post: Download Notifications actions. Informated by Giáo Dục Việt Á selection and synthesis along with other related topics.

  I accidentally started the download/install process for the Android 11 beta, can I cancel it?

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *