找不到符号类NotificationManagerCompat

问题描述:

我正在尝试构建一种通知方法,当检测到特定的信标时,会导致通知出现在锁定的屏幕上。我的理解是,我需要在下面的代码包括.setVisibility(0):找不到符号类NotificationManagerCompat

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); 

} 

我上面的代码,但是当我运行它,它说:“无法找到符号变量SetVisibility”。我在网上做了一些研究,似乎我需要进口这样的:

import android.support.v4.app.NotificationManagerCompat; 

但是,如果我有这个import语句,它会说“找不到符号类NotificationManagerCompat”

我应该怎么办?我已经安装了Android的支持库SDK,并有“项目的libs文件夹Android的支持,v4.jar

也许你有这样的错误上来,因为你增加了一个新的模块到项目中。

要修复它,改变minSdkVersiontargetSdkVersionbuildToolsVersioncompileSdkVersion到原来的模块中匹配build.gradle

之后设置minifyEnabledfalse

它所实际工作y固定它(当使用Android Studio 3.0.1时)将facebook设置为

compile 'com.facebook.android:facebook-android-sdk:4.26.0' 

还检查您的其他库和依赖项以及您的构建文件。

我当前构建文件:

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' 
     } 
    } 
}