elliptic1
elliptic1

Reputation: 1752

Android L Notification.Builder.setVisibility() not resolved by Android Studio

I'm having trouble using android.app.Notification.Builder.setVisibility() from Android L. I've updated Android Studio to Beta, downloaded the L SDK, and set my compileSdkVersion and targetSdkVersion to 20. But Android Studio still can't resolve the setVisibility method.

(Edit: I updated the compileSdkVersion and targetSdkVersion based on comments below, and updated my support libraries from 20.+ to 21.+ )

Without the setVisibility() line my code compiles and runs. I get the same errors if I try NotificationCompat.Builder instead.

Does anyone know how to fix this?

android {
  compileSdkVersion 'android-L'  // was 20
  buildToolsVersion '20'
  defaultConfig {
    minSdkVersion 13
    targetSdkVersion 'L'  // was 20
  ...
  ...

compile 'com.android.support:support-v13:21.+'
compile 'com.android.support:appcompat-v7:21.+'


import android.app.Notification;

...

 noti = new Notification.Builder(InfoPanel.getContext())
                    .setContentTitle(notiTitle)
                    .setContentText("text")
                    .setSmallIcon(notifyIcon)
                    .setOngoing(true)
                    .addAction(firstActionIcon, firstActionText, firstActionPI)
                    .addAction(R.drawable.optionsmenuicon, InfoPanel.getContext().getString(R.string.options), piOptions)
                    .addAction(R.drawable.exit, InfoPanel.getContext().getString(R.string.remove), piExitNotification)
                    .setContentIntent(upperPendingIntent)
                    .setPriority(Notification.PRIORITY_HIGH)
                    .setVisibility(VISIBILITY_PUBLIC)
                    .build() ;

I get the IDE errors "Cannot resolve method 'setVisibility(?)'" and "Cannot resolve symbol 'VISIBILITY_PUBLIC'"

Edit: The first Gradle build error "Cannot resolve method 'setVisibility(?)'" is gone after I updated my compileSdkVersion, but it still shows as red in the IDE. The second error is still in both places.

Upvotes: 1

Views: 3359

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 200120

setVisibility is not in API level 20 - it is API level L, which is currently in preview. Make sure you are targeting the right API level and include the revision 21-rc1 version of the support library (which forces you to target L only).

Upvotes: 3

Related Questions