我已阅读网站上的许多帖子,我相信为了弹出基本通知,不需要编写许多代码行。未出现Android通知
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i("StartUpActivity", "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_up);
NotificationManager notiManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setContentTitle("Hello")
.setContentText("hello")
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(false);
notiManager.notify(0, mBuilder.build());
Log.i("here", "here");
}
我也试过Notification.Builder,它也不起作用。我不知道问题出在哪里。由于intent/pendingintent对通知是可选的,我只是没有添加代码。 (虽然即使我添加意图通知不显示)
我也添加权限VIBRATE在清单,我不知道的用法。
我只想知道如何在状态栏上弹出通知。谢谢。
贵 “这里” 的日志来了吗? – dymmeh
它似乎干净,不知道尝试将ID从0改为另一个正数,看看它是否有效。 –
尝试了你的代码,因为它的工作原理非常好! –