1

Based on the received comments and links i modified the code like this to support android 8.0, but still the notification is not coming up, not getting any clue --

NotificationManager mNotifyManager;
        NotificationCompat.Builder mBuilder;
        NotificationChannel channel;

protected void onPreExecute() {
            super.onPreExecute();
            if(Build.VERSION.SDK_INT < 26)
            {
                mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            }
            else {
                mNotifyManager =
                        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                channel = new NotificationChannel("default",
                        "Channel name",
                        NotificationManager.IMPORTANCE_DEFAULT);
                channel.setDescription("Channel description");
                mNotifyManager.createNotificationChannel(channel);
            }

            mBuilder = new NotificationCompat.Builder(context, "default");
            mBuilder.setContentTitle("File Download")
                    .setContentText("Download in progress")
                    .setSmallIcon(R.mipmap.ic_launcher);

            Toast.makeText(context, "Downloading the file...", Toast.LENGTH_SHORT).show();

        }

protected void onProgressUpdate(Integer... progress) {

            mBuilder.setProgress(100, progress[0], false);
            // Displays the progress bar on notification
            mNotifyManager.notify(0, mBuilder.build());
        }

        protected void onPostExecute(Void result){
            mBuilder.setContentText("Download complete");
            // Removes the progress bar
            mBuilder.setProgress(0,0,false);
            mNotifyManager.notify(0, mBuilder.build());
        }

Based on the received comments and links i modified the code like this to support android 8.0, but still the notification is not coming up, not getting any clue

  • you forget to add your builder to manager `Notification n = mBuilder .build(); mNotifyManager.notify(YOUR_NOTIF_ID, n);` – Hemant Parmar Jan 23 '18 at 07:10
  • I edited the duplicates to add a link to a better example: https://stackoverflow.com/a/44524976. It's much easier to understand. Just make sure to change to the correct `NotificationCompat.Builder` constructor after you create the channel. – Mike M. Jan 23 '18 at 07:20
  • Are you certain that `onProgressUpdate()` is being called? – Mike M. Jan 23 '18 at 08:05
  • ya that's working great in kitkat – Jimmy Gupta Jan 23 '18 at 08:50
  • OK, I just tested your code with a simple `doInBackground()`, and it actually crashed the SystemUI on my API 26 emulators repeatedly, to the point where I couldn't do anything but wipe them. I pulled the `Notification` out, tested it alone, and same thing. Turns out the mipmap was the problem. I changed it to a regular `R.drawable`, and it worked without a hitch. Give that a try. I'm gonna see if I can find any issues that have been filed on this. – Mike M. Jan 23 '18 at 09:19
  • @MikeM..............thnx man, it solved my issue, removed mipmap and added drawable – Jimmy Gupta Jan 23 '18 at 10:59
  • @MikeM.........cheers and thnx man – Jimmy Gupta Jan 23 '18 at 12:56

0 Answers0