Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchMethodError: android.app.Notification$Builder.setColor

final Notification.Builder mBuilder = new Notification.Builder(this)
                .setSmallIcon(R.drawable.bwf_logo)
                .setColor(getResources().getColor(android.R.color.white)) // **exception raised at this line**
                .setContentTitle("Title")
                .setStyle(
                        new Notification.BigTextStyle()
                                .bigText(notificationMessage))
                .setAutoCancel(true)
                .setSound(
                        RingtoneManager
                                .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setVibrate(vibrate).setContentText(notificationMessage);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

01-17 21:14:44.450: W/dalvikvm(27472): threadid=38: thread exiting with uncaught exception (group=0x41004318)
01-17 21:14:44.450: E/AndroidRuntime(27472): FATAL EXCEPTION: IntentService[GCMIntentService]
01-17 21:14:44.450: E/AndroidRuntime(27472): java.lang.NoSuchMethodError: android.app.Notification$Builder.setColor
01-17 21:14:44.450: E/AndroidRuntime(27472):    at com.bwf.betswithfriends.GCMIntentService.gcmAlternateStakeNotification(GCMIntentService.java:109)
01-17 21:14:44.450: E/AndroidRuntime(27472):    at com.bwf.betswithfriends.GCMIntentService.onHandleIntent(GCMIntentService.java:51)
01-17 21:14:44.450: E/AndroidRuntime(27472):    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
01-17 21:14:44.450: E/AndroidRuntime(27472):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-17 21:14:44.450: E/AndroidRuntime(27472):    at android.os.Looper.loop(Looper.java:137)
01-17 21:14:44.450: E/AndroidRuntime(27472):    at android.os.HandlerThread.run(HandlerThread.java:60)
01-17 21:14:44.560: D/dalvikvm(27472): GC_CONCURRENT freed 3520K, 16% free 22535K/26695K, paused 14ms+24ms, total 131ms

Support Library is up to date :-

enter image description here

like image 217
Scorpion Avatar asked Jul 15 '26 08:07

Scorpion


1 Answers

setColor() is new to API Level 21 and will not work on older devices.

I strongly recommend that you switch to NotificationCompat.Builder, as it will allow you to call setColor() and will simply skip that work on older devices.

like image 154
CommonsWare Avatar answered Jul 17 '26 23:07

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!