Custom notification Notification: notify their definition display style drop-down after the Notification

Note: Some of the following methods need to be modified in order to use minSdkVersion 21 years build.gradle

Just add on the build common Notification of builder builder of bigContentView property to RemoteView (custom notification style), such as the need to expand the view to inform the UI control settings in RemoteView monitor, by setting the broadcast and RemoteView of setOnClickPendingIntent () methods used in conjunction with

Notification the Notification;
the NotificationManager Manager;
static the Receive the receive;
// send a notification custom view
public void the sendNotification () {
Notification.Builder Builder = new new Notification.Builder (the this);
builder.setSmallIcon (R.drawable.ic_launcher_background); // set small icon (not expanded above the display icon)
builder.setTicker ( "QlynMusic and out of songs, come listen to it"); // display at the top of the first notification received
builder.setWhen (System.currentTimeMillis ()); // transmission time
builder.setAutoCancel (false); // whether to cancel the notification after click the notification
builder.setWhen (System.currentTimeMillis ()); // set time notifications
// setVisibility to set notifications appear under what circumstances
/ *
Notification.VISIBILITY_PUBLIC: no circumstances will display a notification.
Notification.VISIBILITY_PRIVATE: only if there is no lock screen displays a notification.
Notification.VISIBILITY_SECRET: to be able to display a notification in the case of a safety lock and no lock screen pin, password and so on.
* /
Builder.setVisibility (Notification.VISIBILITY_PUBLIC);

// set event notification response Activity, PendingIntent delay can be understood as the Intent
the Intent the Intent Intent new new = (the this, MainActivity.class);
the PendingIntent pendingIntent = PendingIntent.getActivity (the this, 0 , Intent, 0);
builder.setContentIntent (pendingIntent);

// set notice vibration: the subscript represents a long rest is even, odd length vibration milliseconds
// need to place the registration authority statement:
// <-permission uses Android: name = "android.permission.VIBRATE" />
Long [] = {0,1000,1000,1000 vibrates}; // Now case vibration and the stationary one second, then a vibration
builder.setVibrate (vibrates);

// construct a notification the notification
notification builder.build = ();
// get a custom view
= new new RemoteViews RemoteViews (getPackageName (), R.layout.information);
// set in the remote display picture
remoteViews.setImageViewResource (R.id.nAlbum, android.R.drawable.btn_star_big_on);
remoteViews.setImageViewResource (R.id .nAppIcon, R.mipmap.ic_launcher);
remoteViews.setImageViewResource (R.id.nLastSong, android.R.drawable.ic_media_previous);
IF (mediaPlayer.isPlaying ()) {
remoteViews.setImageViewResource (R.id.nPlay, R. drawable.pause);
} the else {
remoteViews.setImageViewResource (R.id.nPlay, R.drawable.play);
}
remoteViews.setImageViewResource (R.id.nNextSong, android.R.drawable.ic_media_ff);

// set in RemoteViews the control monitoring, used in conjunction with the broadcast receiver.
intent = new Intent ( "play" ); // Set Action intent of (http://www.amjmh.com/v/)
PIntentPause = PendingIntent.getBroadcast the PendingIntent (the this, 0,
intent, 0);
remoteViews.setOnClickPendingIntent (R.id.nPlay, pIntentPause);
intent the Intent new new = ( "lastSong"); // set the intent of the Action
pIntentPause = PendingIntent.getBroadcast (the this, 0,
intent, 0);
remoteViews.setOnClickPendingIntent (R.id.nLastSong, pIntentPause);
intent the Intent new new = ( "nastSong"); // set the intent of the Action
pIntentPause = PendingIntent.getBroadcast (the this, 0,
intent , 0);
remoteViews.setOnClickPendingIntent (R.id.nNextSong, pIntentPause);

// custom view incoming notification expanded view
notification.bigContentView = RemoteViews;
// send a notification
manager = (NotificationManager) getSystemService (NOTIFICATION_SERVICE );
manager.notify( 1,notification );
}
————————————————

Guess you like

Origin www.cnblogs.com/hyhy904/p/11414312.html