郑州app开发android通知栏消息。布局代码比较简单,就不介绍了,布局代码只有一个button按钮。
下面是java代码
package cn.xhhkj.videoview;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.FragmentTransaction;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.BounceInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "结果是";
private ImageView iv_image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void send(View view) {
Notification.Builder builder= new Notification.Builder(this);
builder.setTicker("通知公告:恭喜您获得最佳。");
builder.setAutoCancel(true);
builder.setContentTitle("通知公告");
builder.setContentText("恭喜您获得最佳。");
builder.setSmallIcon(R.drawable.ic_launcher_foreground);
// builder.setOngoing(true);
Intent intent2 = new Intent(this,MainActivity.class);
PendingIntent intent3 =PendingIntent.getActivity(getApplicationContext(),1,intent2,PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(intent3);
Notification notification = builder.getNotification();
NotificationManager mananger = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mananger.notify(1, notification);
// mananger.cancel(1);
}
}