1

PHP / C# / ASP coder starting out in android properly after giving Xamarin a shot (and then having a 6 month hiatus from all coding).

I'm trying to achieve custom layouts within a notification. I can get it to produce normal notifications, but can't help but crash when its done using setContent(view).

Also new to Eclipse / ADT so struggling with knowing how to work through the issues myself (in visual studio this was easy).

Just to clarify, displayNotification is currently set to execute upon app launch.

I am sure it is something so simple and small, however it's getting late and my mind is frazzled. All help is greatly appreciated!

Here is my code (removed any commented out code just to clean it up for this purpose).

protected void displayNotification() {

RemoteViews customNotificationView = 
new RemoteViews(getPackageName(), R.layout.notification_layout);

NotificationCompat.Builder  mBuilder = 
new NotificationCompat.Builder(this);   

mBuilder.setContent(customNotificationView);
mBuilder.setTicker("New Message Alert!");
mBuilder.setSmallIcon(R.drawable.ic_launcher);

mBuilder.setOngoing(true);

mNotificationManager = (NotificationManager) 
getSystemService(Context.NOTIFICATION_SERVICE);

mNotificationManager.notify(notificationID, mBuilder.build());
}

Here is my custom layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/notification_title"
    style="@style/NotificationTitle" 
    />


<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>
Luke Wale
  • 13
  • 2

1 Answers1

2

I tested your code and it seems to be working fine without the SeekBar in the layout. Based on this answer you can't add a Seek bar on a notification layout. I will look better and comment latter.

Edit: You can try to change the seek bar to buttons and add onClick listeners to them, here is a start point. Adding onClick Action To Button In Notification

Community
  • 1
  • 1
dinhokz
  • 895
  • 15
  • 36
  • 1
    Thanks! I'll have a look when I can get on to my computer. I never considered changing the xml to test (bit silly really... but I learn). From what I've read it should definitely be possible, but seems like it's more complicated than I expected. All a good starting point either way. Thank you. – Luke Wale May 23 '14 at 10:39
  • 1
    As you said - remove the seekbar and then it works. I spent some more time looking around and it seems a brick wall when it comes to a seekbar... however I did notice an app replicating a seekbar in the notifications. [link](https://play.google.com/store/apps/details?id=com.mortisapps.trayvolume). Playing around with that, you can't slide, however you can press different locations - so I guess it is a case of using buttons and somehow styling to look like a seekbar. This is likely to be my direction now. – Luke Wale May 24 '14 at 18:03
  • I have also seen some apps and noticed the same thing, but I think it is not an easy task to make this. What you can do is make two buttons "up" and "down" and show the progress as percentage.Can you mark as right answer? – dinhokz May 24 '14 at 18:51