0
我试图建立一个通知方法,当检测到一个特定的信标时,会导致通知出现在锁定的屏幕上。我的理解是,我需要在下面的代码包括.setVisibility(0):找不到符号方法setVisibility(int)
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(INT)”。我在网上做了一些研究,似乎我需要进口这些:
import android.support.v4.app.NotificationCompat;
import android.app.Notification;
import android.app.NotificationManager;
即使我有这些进口,我仍然得到同样的错误消息。谁能帮忙?谢谢!!
作为他用NotificationCompat,他应该定位API 22所以你应该改变你的版本代码LOLLIPOP_MR1 :) –
感谢这两个,我试图添加上面的代码,但它说“找不到符号变量棒棒糖” .. ..我需要做些什么来解决这个问题? –
它不应该得到错误。请同步项目并清理然后重建项目。如果错误,那么你得到什么gradle错误? – Queendevelopers