Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom status bar notification for background download
    primarykey
    data
    text
    <p>I am new to android development and I try to create a background download feature for my app. I followed this <a href="http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomExpandedView" rel="nofollow">http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomExpandedView</a> to create my custom notification.</p> <p>The downloading is performed, I checked the downloaded file in the sdcard. Also,the status bar icon and title are changed properly.</p> <p><strong>The problem is that the custom layout I provide for the notification does not appear (expand under the bar).</strong> Here is the related code parts inside private AsyncTask class:</p> <pre><code> @Override protected void onPreExecute() { // create and configure the notification notification = new Notification(R.drawable.download, "Downloading map..", System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT; //create a custom layout for the notification myContentView = new RemoteViews(appContext.getPackageName(), R.layout.download_progress); myContentView.setImageViewResource(R.id.status_icon, R.drawable.ic_menu_save); myContentView.setTextViewText(R.id.status_text, "download in progress"); myContentView.setProgressBar(R.id.status_progress, 100, 0, false); notification.contentView = myContentView; notification.contentView.apply(appContext, dl.getListView()); //instantiate the pending intent Intent myIntent = new Intent(appContext, DownloadList.class); myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); int requestID = (int) System.currentTimeMillis(); PendingIntent myPendingIntent = PendingIntent.getActivity(appContext, requestID, myIntent, 0); notification.contentIntent = myPendingIntent; //add the Notification object to the notification manager notificationManager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIF_ID, notification); } @Override protected void onProgressUpdate(Integer... progress) { //update progress bar notification.contentView.setProgressBar(R.id.status_progress, 100, progress[0], false); notificationManager.notify(NOTIF_ID, notification); } } </code></pre> <p>Note that my DownloadList class extends ListActivity.</p> <p>Do I need to do something more that just "notification.contentView = myContentView;" in order to inflate the layout?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload