• 15
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I am downloading a pdf file and notification for download is visible in marshmallow but it is not Visible in Android P.

My Files downloads successfully in both Android-M and Android-P

My code is here.

public static long DownloadData (Uri uri, Context context,String dir,String fileName,String title,String discription) {
        if(title==null){
            title="";
        }
        if(discription==null){
            discription="";
        }
        long downloadReference;
        final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        // Create request for android download manager
        downloadManager = (DownloadManager)context.getSystemService(DOWNLOAD_SERVICE);
        DownloadManager.Request request = new DownloadManager.Request(uri);
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
        request.setVisibleInDownloadsUi (true);
        request.setNotificationVisibility (DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        request.addRequestHeader("Authorization", "Bearer " + sp.getString(SharedPreferenceKeys.PREF_AUTH_TOKEN, "Woof"));

        //Setting title of request
        request.setTitle(title);
        //Setting description of request
        request.setDescription(discription);
            request.setDestinationInExternalPublicDir(
                    dir,fileName);
               //Enqueue download and save into referenceId
        downloadReference = downloadManager.enqueue(request);

        return downloadReference;
    }

Can anyone give solution to show Download Notification in Android P as well? thanks.

If Project target Android 9.0 (API level 28), You Need to add FOREGROUND_SERVICE permission in manifest.

Add Below code to your Manifest file

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

Note: Apps that target Android 9.0 (API level 28) or higher and use foreground services must request the FOREGROUND_SERVICE permission. This is a normal permission, so the system automatically grants it to the requesting app.

  • 1
Reply Report