问题
I am trying to build a notification method that would result in a notification appearing on the locked screen when a particular beacon is detected. My understanding is that I need to include .setVisibility(0) in the following code:
public void showNotification(Beacon beacon) {
Resources r = getResources();
int random = (int)System.currentTimeMillis();
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(android.R.drawable.ic_popup_reminder)
.setContentTitle("Beacons Found")
.setContentText(beacon.getID().toString())
.setVisibility(0) // allow notification to appear on locked screen
.setAutoCancel(true)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(random, notification);
}
I have the above code, but when I run it it says "cannot find symbol variable SetVisibility". I have done some research online and it seems I need to import this:
import android.support.v4.app.NotificationManagerCompat;
But if I include this import statement, it would say "cannot find symbol class NotificationManagerCompat"
What should I do? I have already installed Android Support Repository SDK and have the "android-support-v4.jar in the libs folder of the project
回答1:
Maybe you have this error come up, because you added a new module to your project.
To fix it, change minSdkVersion
, targetSdkVersion
, buildToolsVersion
, and compileSdkVersion
to match the build.gradle
in your original module.
After that set minifyEnabled
to false
.
What it actually fixed it for me (while using Android Studio 3.0.1) was setting facebook to
compile 'com.facebook.android:facebook-android-sdk:4.26.0'
Also check your other libs and dependencies and your build file.
My current build file:
allprojects {
repositories {
jcenter()
maven {
url "http://repo1.maven.org/maven2"
}
// maven {
// url 'https://maven.google.com'
// }
// since Android Studio 3.0.0
// or google()
flatDir {
dirs 'libs'
}
}
}
来源:https://stackoverflow.com/questions/43259902/cannot-find-symbol-class-notificationmanagercompat