6

音楽の再生が停止するまで通知バーに表示される通知が必要です。現在、通知を表示できるコードをいくつか書いていますが、通知のクリアボタンを押すか、それを交換すると、通知センターから消えます。音楽の再生を停止するまでバーに留まる Spotify のような通知が必要です。これが通知用の私のコードです

int pendingRequestCode = 0;
 // final Resources res = getResources();
    notificationManager = (NotificationManager) getSystemService(
           NOTIFICATION_SERVICE);
   Intent i = new Intent(getApplicationContext(),Mainactivity.class);   
   Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_action_search)
.setAutoCancel(true)
.setTicker("test ckick")    
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), NOTIFICATION_DEFAULT, i,0));


       // Sets a custom content view for the notification, including an image button.
        layout = new RemoteViews(getPackageName(), R.layout.notification);
       layout.setTextViewText(R.id.notification_title, getString(R.string.app_name));
       Intent clickIntent = new Intent();
       clickIntent.setAction(ACTION_DIALOG);
       PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), pendingRequestCode, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
       layout.setOnClickPendingIntent(R.id.notification_button,pendingIntent);
       builder.setContent(layout);

       // Notifications in Android 3.0 now have a standard mechanism for displaying large
       // bitmaps such as contact avatars. Here, we load an example image and resize it to the
       // appropriate size for large bitmaps in notifications.

       layout.setImageViewResource(R.id.notification_button, R.drawable.pause);
   notificationManager.notify(NOTIFICATION_DEFAULT, builder.getNotification());

返事を待っています ここに画像の説明を入力

4

2 に答える 2

19

setOngoing(true)イベントが進行中であることを示すために使用します。ユーザーがタップするとsetAutoCancel(true)がクリアされるため、を削除することもできます。Notification

于 2012-10-26T09:29:43.980 に答える
0

notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL

于 2012-10-26T09:40:18.597 に答える