2017-04-06 178 views
0

我正在嘗試構建一種通知方法,當檢測到特定的信標時,會導致通知出現在鎖定的屏幕上。我的理解是,我需要在下面的代碼包括.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

回答

0

也許你有這樣的錯誤上來,因爲你增加了一個新的模塊到項目中。

要修復它,改變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' 
     } 
    } 
}