android中的横幅通知
1.这个是点击按钮notice,然后按钮发送一个横幅通知 ,如果不想实现的话,可以剪切Onclick里面的内容
notice = findViewById(R.id.notice);
notice.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String id = "my_channel_01";String name = "我是渠道名字";NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);Notification notification = null;
// 设置要跳转的页面Intent intent = new Intent(MainActivity.this, NotificationActivity.class);
// 要传递到下一个页面的数据intent.putExtra("result", "Main函数要传递的参数");PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);//延迟跳转if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW);notificationManager.createNotificationChannel(mChannel);notification = new Notification.Builder(MainActivity.this, "default").setChannelId(id)
// 设置标题.setContentTitle("中奖五百万!!消息的标题").setContentText("消息的内容").setSmallIcon(R.mipmap.ic_launcher)
// 点击横幅自动跳转.setContentIntent(pendingIntent)
// 点击横幅自动消失.setAutoCancel(true).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)).build();} else {NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this, "default").setContentTitle("中奖五百万!!消息的标题").setContentText("消息的内容").setSmallIcon(R.mipmap.ic_launcher).setOngoing(true).setAutoCancel(true).setContentIntent(pendingIntent).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)).setChannelId(id);notification = notificationBuilder.build();}notificationManager.notify(111123, notification);}});
2.接受的页面
activity_notification.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".NotificationActivity"><ImageViewandroid:id="@+id/imageView2"android:layout_width="378dp"android:layout_height="379dp"android:scaleType="fitXY"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"app:srcCompat="@mipmap/be" /><TextViewandroid:id="@+id/t1"android:layout_width="224dp"android:layout_height="69dp"android:layout_marginStart="28dp"android:layout_marginLeft="28dp"android:layout_marginTop="36dp"android:gravity="center"android:text="TextView"android:textSize="30dp"android:textStyle="bold"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toBottomOf="@+id/imageView2" />
</androidx.constraintlayout.widget.ConstraintLayout>
NotificationActivity.java
package com.example.myapplication;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;public class NotificationActivity extends AppCompatActivity {private TextView t1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_notification);Intent intent = getIntent();String str = intent.getStringExtra("result");Log.d("Notification",str);t1=findViewById(R.id.t1);t1.setText(str);}
}
效果图
安卓更新太快了,希望你们不要像我一样遇到烦恼
android中的横幅通知相关推荐
- android 实现定时通知,在Android中创建定时通知(例如,针对事件)
对于某些Android应用程序,我想集成以下功能: 用户可以定义他想要被提醒的时间.当时间到了,应用程序应该在通知栏中创建通知,即使此时用户没有使用该应用程序. 为此,需要查看AlarmManager ...
- Android——横幅通知
横幅通知,也称为提醒式通知,效果如下图: 这个效果在QQ,微信,钉钉等一些主流的App当中,大家一定很熟悉,今天就来说说如何实现. 可能会触发提醒式通知的条件有如下3种: 用户的Activiity处于 ...
- Android 12 悬浮通知/横幅通知状态栏应用图标显示不全
先看下问题的表现情况吧 这个模块的实现在SystemUI 这里先列举下与这个模块以及本文要描述的相关代码和资源文件,后面逐个分析 SystemUI/src/com/android/systemui/s ...
- Android笔记——横幅通知
通知分为三种:下拉通知.锁屏通知.横幅通知.前两个通知内容是相同的,横幅通知的View需要单独定制(还有一种是只在通知栏出现一句话) 一般的app,只会默认开启"下拉通知"的权限. ...
- Java中集成极光推送实现给Android提送消息通知(附代码下载)
场景 Android中集成极光推送实现推送消息通知与根据别名指定推送附示例代码下载: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details ...
- Android中集成Jpush实现推送消息通知与根据别名指定推送附示例代码下载
场景 经常会有后台服务向Android推送消息通知的情况. 实现 首先在Android Studio中新建一个Android应用 在Project根目录的build.gradle中配置了jcenter ...
- Android Notification 手机系统横幅弹出提示框调用,横幅通知,RemoteViews使用实例
直接上代码 :bundle是极光推送的bundle @Override public void onReceive(Context context, Intent intent) {try {Bund ...
- android10代码开启横幅通知,Android通知以编程方式启用横幅设置
是否有任何方法可以通过编程方式在应用程序通知中打开横幅设置(显示在状态栏顶部)? // send notification to NotificationManager Notification.Bu ...
- Android中的通知Notification
1.获得系统服务 notificationmanager=(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); 2 ...
最新文章
- html给radio添加图片,使用纯CSS自定义radio(单选框)和checkbox(多选框)的样式
- ITK:将静态密集2D级别集可视化为高程图
- MongoDB学习笔记一ID自增长
- 一步一步学习 iOS 6 编程(第四版)正式发布!
- CodeForces - 976F Minimal k-covering
- 多php共用一个mysqli连接,在pHP中使用MySQLi连接到多个数据库
- linux ls for 命令嵌套
- python爬虫实现方式_python爬虫的实现方法
- 嵌入式linux加载引导内核和根文件系统的方法
- poidoc转换成html乱码,JAVA 利用POI实现DOC转HTML的方法及BUG修改
- 也谈谈古代一两银子相当于今天的价格
- 代码审计——你是如何发现那些有缺陷的代码的
- MAC干净卸载IDEA
- SAP 批量导出客户主数据
- 平安证券的竟借用咱对青海明胶的一分析文章
- 雄牛PVC地板革新胶地板行业成环保绿色新选择
- xls/csv文件转换成dbf文件
- 《惢客创业日记》2021.07.26-31(周日)惢客与征信的区别(上)
- Laravel9+Layui实现的低代码开发平台
- Ubuntu18.04 peda安装
热门文章
- Android SurfaceFlinger 学习之路(五)----VSync 工作原理
- Common lisp之加载方式(一)
- 启动另一个Activity、Service、应用程序
- warning: control reaches end of non-void function:错误解决
- Java之添加环境变量
- directsound之播放pcm
- 深度学习自学(三十五):双向图推理全景图像分割
- 如何在浏览器中显示本地文件系统_如何完全卸载浏览器中的Flash插件
- windows_server2012搭建iis并配置http重定向 iis转发
- linux 与win共享文件夹