2
我是一名Android初學者。我想在我的應用程序中顯示通知。我用下面的代碼在Android中顯示通知而無需使用意圖
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = "";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Hello";
CharSequence contentText = "Welcome ";
Intent notificationIntent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, null, 0);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notificationManager.notify(HELLO_ID, notification);
但我的問題是,每當運行我的應用程序的意圖加載圖標。然後將圖標顯示在狀態欄。如何在不使用意圖的情況下顯示通知?請幫助