2014-02-16 16 views

回答

0

通知是一個類,它代表狀態欄中的持久性圖標,可通過啓動器訪問,打開或閃爍設備上的LED,或通過閃爍背光燈,播放聲音提醒用戶,或振動。

通知管理是一流的,它允許你通知添加到系統中,

startForegroundSerivce類的方法。例如在你的Service類中你可以有這樣的事情。

Intent notificationIntent = new Intent(this, ActivityMain.class); 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
    builder.setContentIntent(pendingIntent) 
       .setSmallIcon(R.drawable.ic_stat_play) 
       .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) 
       .setTicker(getString(R.string.app_name)) 
       .setWhen(System.currentTimeMillis()) 
       .setOngoing(true) 
       .setContentTitle(getString(R.string.app_name)) 
       .setContentText(someText); 
    Notification notification = builder.build(); 

    startForeground(1, notification); 
0

一個Notification是要發生,提醒的東西,用戶的事情的描述 - 什麼圖標後進入在狀態欄中,播放什麼鈴聲等。

NotificationManager是一個系統服務,可以顯示Notification

我想用startForeground梅索德並且不能與NotificationManager

正確的使用它。使用Notification.Builder(或NotificationCompat.Builder)創建Notification。有關使用startForeground()的示例,請參見this project

相關問題