java - 收到消息时通知如何工作

标签 java android notifications sms

我正在使用应用程序来接收消息,但我想在接收消息时显示通知

请问工作怎么样

最佳答案

PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), Player.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_UPDATE_CURRENT);
notification = new Notification();
notification.tickerText = "App Name";
notification.icon = R.drawable.icon;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
try {
        notification.setLatestEventInfo(getApplicationContext(), "App Name", "AppName~ ", pi);
} catch (Exception e) {

        e.printStackTrace();
}
startForeground(01, notification);

关于java - 收到消息时通知如何工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20259767/

相关文章:

MongoDb 集合 findAll() 上的 Java NullPointerException

java - Dozer - 排除嵌套对象

java - Playframework Ebean.Save() 给出连接关闭

java - 如何检查 fragment 在 Activity OnBackpressed 中是否可见

Android - 在静态类中使用通用图像加载器

android - 如何检查 View 小部件的类型?

android - 是否可以使用Flutter框架在Android中显示通知?

java - 为什么 Java 7 和 Eclipse 3.8 编译器无法使用新的 Java 7 菱形运算符编译 JDK 代码?

google-chrome - 是否可以设置 Chrome 显示的通知样式?

android - Android如何在android本地通知中添加视频和GIF?