2016-04-08 14 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

「通知」ではなく「通知コード」を使用してください。 –

答えて

0

フラグを設定中にこのコードを追加:
notification.defaults | = Notification.DEFAULT_SOUND; notification.defaults | = Notification.DEFAULT_VIBRATE; notification.defaults | =通知..DEFAULT_LIGHTS; notification.flags | = Notification.FLAG_AUTO_CANCEL;

+0

どこにこれを追加しますか?上記のコードで追加した場合、電話機は振動を止めることはありません。私はそれが正しい場所ではないと推測しています。 –

+0

以下のコードを置き換えて追加してください:notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; – raasesh

関連する問題