[Android] Avoid notification crash on 3.2 because Google Compat libary is

Jean-Baptiste Kempf git at videolan.org
Mon Oct 15 15:20:53 CEST 2012


vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Mon Oct 15 15:20:36 2012 +0200| [13ae03c797352b116979ab06c1733241b3531eb9] | committer: Jean-Baptiste Kempf

Avoid notification crash on 3.2 because Google Compat libary is
broken...

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=13ae03c797352b116979ab06c1733241b3531eb9
---

 vlc-android/src/org/videolan/vlc/AudioService.java |   35 ++++++++++++--------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index d430925..727519b 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -454,25 +454,32 @@ public class AudioService extends Service {
     };
 
     private void showNotification() {
-        // add notification to status bar
-        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
+        try {
+            // add notification to status bar
+            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
             .setSmallIcon(R.drawable.icon)
             .setLargeIcon(AudioUtil.getCover(this, mCurrentMedia, 64))
             .setContentTitle(mCurrentMedia.getTitle())
             .setContentText((Util.isJellyBeanOrLater() ? mCurrentMedia.getArtist()
                     : mCurrentMedia.getArtist() + " - " + mCurrentMedia.getAlbum()))
-            .setContentInfo(mCurrentMedia.getAlbum())
-            .setAutoCancel(false)
-            .setOngoing(true);
-
-        Intent notificationIntent = new Intent(this, AudioPlayerActivity.class);
-        notificationIntent.setAction(Intent.ACTION_MAIN);
-        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
-        notificationIntent.putExtra(START_FROM_NOTIFICATION, true);
-        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
-
-        builder.setContentIntent(pendingIntent);
-        startForeground(3, builder.build());
+                    .setContentInfo(mCurrentMedia.getAlbum())
+                    .setAutoCancel(false)
+                    .setOngoing(true);
+
+            Intent notificationIntent = new Intent(this, AudioPlayerActivity.class);
+            notificationIntent.setAction(Intent.ACTION_MAIN);
+            notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+            notificationIntent.putExtra(START_FROM_NOTIFICATION, true);
+            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
+
+            builder.setContentIntent(pendingIntent);
+            startForeground(3, builder.build());
+        }
+        catch (NoSuchMethodError e){
+            // Compat library is wrong on 3.2
+            // http://code.google.com/p/android/issues/detail?id=36359
+            // http://code.google.com/p/android/issues/detail?id=36502
+        }
     }
 
     private void hideNotification() {



More information about the Android mailing list