2016-04-08 71 views
1

我想關閉通知刷卡,但它只是不會關閉。我試圖設置正確的標誌以及設置OnGoing爲false,但我沒有運氣。關閉通知刷卡不工作

這是我的代碼有:

Notification notification = new Notification.Builder(getBaseContext()) 
        .setSmallIcon(R.drawable.appicon) 
        .setContentTitle("My notification") 
        .setContent(remoteViews) 
        .setAutoCancel(true) 
        .setOngoing(false) 
        .build(); 

      notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; 

     // Additional code 

     Intent playpause = new Intent(); 
     playpause.setAction("com.eciflow.project.pause"); 
     PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 1, playpause, PendingIntent.FLAG_CANCEL_CURRENT); 

     Intent stop = new Intent(); 
     stop.setAction("com.eciflow.project.stop"); 

     PendingIntent stopI = PendingIntent.getBroadcast(getApplicationContext(), 1, stop, PendingIntent.FLAG_CANCEL_CURRENT); 
     remoteViews.setImageViewResource(R.id.playpause, R.drawable.pauseradio); 
     remoteViews.setImageViewResource(R.id.stop, R.drawable.stopradio); 
     remoteViews.setOnClickPendingIntent(R.id.playpause, pi); 

     remoteViews.setOnClickPendingIntent(R.id.stop, stopI); 
     remoteViews.setTextViewText(R.id.title, "Playing"); 
     remoteViews.setTextViewText(R.id.text, param2); 
     remoteViews.setTextColor(R.id.title, getResources().getColor(android.R.color.holo_blue_dark)); 
     remoteViews.setTextColor(R.id.text, getResources().getColor(android.R.color.holo_blue_dark)); 


     startForeground(250, notification); 

我在玩音樂從流背景...

任何想法,爲什麼發生這種情況?如果還有其他選擇,我也願意改變結構。

謝謝!

+0

嘗試使用「NotificationCompat」而不是「通知」。 –

回答

0

添加此代碼設置標誌時:
notification.defaults | = Notification.DEFAULT_SOUND; notification.defaults | = Notification.DEFAULT_VIBRATE; notification.defaults | = Notification.DEFAULT_LIGHTS; notification.flags | = Notification.FLAG_AUTO_CANCEL;

+0

我在哪裏添加這個?如果我在上面的代碼中添加了,手機不會停止振動。我猜這不是正確的地方。 –

+0

添加替換下面的代碼:notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; – raasesh