进度通知未在Android 8.0中显示

时间:2018-01-23 07:07:30

标签: android android-notifications android-8.0-oreo

基于收到的评论和链接我修改了这样的代码以支持Android 8.0,但仍然没有提出通知,没有得到任何线索 -

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());
        }

根据收到的评论和链接,我修改了这样的代码,以支持Android 8.0,但仍然没有通知,没有得到任何线索

0 个答案:

没有答案